aws-sdk-net: Invoke Lambda function failed with Unity 2017.1.0f3

After upgrade to Unity 2017.1.0, all Lambda function failed to invoke. The LambdaExample provided with the plugin aws-sdk-unity_3.3.121.0 also failed.

Expected Behavior

Call function via InvokeAsync should work without exception

Current Behavior

With the LambdaExample, clicking the Invoke button cause an exception:

InvalidOperationException: Cannot override system-specified headers
UnityEngine.Networking.UnityWebRequest.SetRequestHeader (System.String name, System.String value) (at C:/buildslave/unity/build/artifacts/generated/common/modules/UnityWebRequest/WebRequestBindings.gen.cs:479)
UnityEngine.WWW..ctor (System.String url, System.Byte[] postData, System.Collections.Generic.Dictionary`2 headers) (at C:/buildslave/unity/build/Runtime/WebRequestWWW/UWRWWW.cs:62)
Amazon.Runtime.Internal.UnityMainThreadDispatcher+<InvokeRequest>d__7.MoveNext ()
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Amazon.Runtime.Internal.UnityMainThreadDispatcher:ProcessRequests()
Amazon.Runtime.Internal.UnityMainThreadDispatcher:Update()

Possible Solution

Not a solution but a workaround mention in https://github.com/aws/aws-sdk-net/issues/643 Add below after UnityInitializer is attached to gameobject

Amazon.AWSConfigs.HttpClient = Amazon.AWSConfigs.HttpClientOption.UnityWebRequest;

Steps to Reproduce (for bugs)

Requirement: Unity 2017.1.0f3 aws-sdk-unity_3.3.121.0

Setup LambdaExample provided in the plugin (Setup Cognito and Region) Run scene Enter function name and press the invoke button

Your Environment

Unity 2017.1.0f3 aws-sdk-unity_3.3.121.0 Windows 10

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 17

Most upvoted comments

Still no update on this? Unity is on 2017.2 now, been out for a while. Why is SDK still broken?

Possible Solution Not a solution but a workaround mention in #643 Add below after UnityInitializer is attached to gameobject

Amazon.AWSConfigs.HttpClient = Amazon.AWSConfigs.HttpClientOption.UnityWebRequest;

Work fine !!

@dave-colenso I have updated my answer to include the compiled assemblies. Hope it helps!

Here’s a temporary fix for Unity 2017.1 versions. Presumably, this should also work in Unity 2017.2 versions if you have the same bug, but I haven’t tested. As mentioned above, all you need is to manually override the target HttpClient interface with UnityWebRequest. To do this, the best way I have found is to add it right after UnityMainThreadDispatcher awakes.

// UnityMainThreadDispatcher.cs
public void Awake()
{
      _logger = Logger.GetLogger(this.GetType());
      // Call the method to process requests at a regular interval.
      _nextUpdateTime = Time.unscaledTime;
      _nextUpdateTime += _updateInterval;

      // Override HttpClient here
     Amazon.AWSConfigs.HttpClient = Amazon.AWSConfigs.HttpClientOption.UnityWebRequest;
}

Simply override the HttpClient in the Awake() method in UnityMainThreadDispatcher.cs code, and compile again. Now everything should be back working again!

Update I have uploaded some compiled DLL assemblies here on Google Drive. This is based on AWS SDK v3.3.186.1 release.