LoginSignup
2
1

More than 5 years have passed since last update.

Unity2017.3 AWSSDKエラーの回避

Last updated at Posted at 2018-02-06

Unity2017.3でのAWSSDKエラーについて

Unity2017.2系で正常に動作していたのに
Unity2017.3.0p4でAWSSDK(正確にはlambdaを使ってた)を使用すると 下記のようなエラーが発生して動作してくれません。

OS:macOS 10.12.6
Unity:Unity2017.3.0p4

Amazon.Lambda.AmazonLambdaException: The request signature we calculated does not match the signature you provided. >Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

AWSSDK.NETのgithubにも同様のissueがあがっていました。
https://github.com/aws/aws-sdk-net/issues/820

原因

いろいろ、調査しましたが どうやら UnityWebRequestの動作が変わったのが影響しているようです。
(AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest; を設定してAWSSDK使用している)

UnityEditorからUnityWebRequest(AWSSDKを使用せずシンプルなコードで)を使って送信内容を確認してみると、Unity2017.3.0p4にのみTransfer-Encoding: chunkedのHeader情報が追加されていました。
どうやらこの影響で、エラーが発生しているようなのです。
(chunkedになることによって、signatureの作成がおかしくなってるんでしょうね。いろいろ調査しましたが。。まあ割愛)

Unity2017.2.0f3

Content-Length: 19
Content-Type: application/json
Accept: /
Accept-Encoding: deflate, gzip
Host: www.kojikoji.net
User-Agent: UnityPlayer/2017.2.0f3 (UnityWebRequest/1.0, libcurl/7.51.0-DEV)
X-Unity-Version: 2017.2.0f3

Unity2017.3.0p4

Transfer-Encoding: chunked
Content-Length: 19
Content-Type: application/json
Accept: /
Accept-Encoding: deflate, gzip
Host: www.kojikoji.net
User-Agent: UnityPlayer/2017.3.0p4 (UnityWebRequest/1.0, libcurl/7.51.0-DEV)
X-Unity-Version: 2017.3.0p4

回避コード

public class HogeHoge : MonoBehaviour
{
    private void Awake()
    {
         // AWSSDKの初期化後に今回のエラー回避用のコンポーネントを追加している
         UnityInitializer.AttachToGameObject(gameObject);
      // this bug workaround code
         // https://github.com/aws/aws-sdk-net/issues/820
         gameObject.AddComponent<CustomUnityMainThreadDispatcher>();
     // その他の初期化処理など..
         AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;
                                
    }
}

CustomUnityMainThreadDispatcherコンポーネントのコード
https://gist.github.com/housei/b38cc93d6e8fe7caa2764d5b0dc34393

修正内容としては本来AWSSDKのUnityMainThreadDispatcherコンポーネントが処理している
web request処理をよこどりして
CustomUnityMainThreadDispatcher側で実行させ、UnityWebRequest.chunkedTransfer = falseに設定することで'Transfer-Encoding: chunkedが追加されないようにしています。

AWSSDK側の修正が入るまでは、この回避方法でしのぎます。
awssdk-netのソースコードを修正してunitypackage化するのが正攻法ですね。
(私の環境がmacでして,Windowsでvisual stduio使えればこのへんサクッとできるかもしれませんね)

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1