Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity AWS s3 SDK - PutObjectAsync Works in unity but not on iOS or in Xcode simulator

Discussion in 'Formats & External Tools' started by PrimordialArtStudios, Jan 7, 2018.

  1. PrimordialArtStudios

    PrimordialArtStudios

    Joined:
    May 10, 2013
    Posts:
    2
    I've been struggling with this one and can't seem to figure out why it is failing. I can run Get/List/Put requests successfully in Unity editor however on my phone and in the Xcode simulator only Get/List work. the Put requests fails with the following error message:

    Error: Amazon.S3.AmazonS3Exception: The request signature we calculated does not match the signature you provided. Check your key and signing method. ---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.

    this is the content of the response:
    Received error response: [<?xml version="1.0" encoding="UTF-8"?>


    <Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>XXXXXXXXXXXX</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA25620180107T032858Z20180107/us-east-1/s3/aws4_request19d036f4270664926f898506ae82bb40350439046a401c0ecae6facab5af423d</StringToSign<SignatureProvided>de0f14b4426a411b60830c44c2eaa2cb185e28f16f04c04969c62c08ed6a709c</SignatureProvided><StringToSignBytes>41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 38 30 31 30 37 54 30 33 32 38 35 38 5a 0a 32 30 31 38 30 31 30 37 2f 75 73 2d 65 61 73 74 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 31 39 64 30 33 36 66 34 32 37 30 36 36 34 39 32 36 66 38 39 38 35 30 36 61 65 38 32 62 62 34 30 33 35 30 34 33 39 30 34 36 61 34 30 31 63 30 65 63 61 65 36 66 61 63 61 62 35 61 66 34 32 33 64</StringToSignBytes><CanonicalRequest>PUT/0001



    the code:
    void Awake() {
    UnityInitializer.AttachToGameObject(this.gameObject);
    AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;
    AWSConfigs.CorrectForClockSkew = true;
    AWSConfigs.RegionEndpoint = RegionEndpoint.USEast1;
    AWSConfigs.LoggingConfig.LogTo = LoggingOptions.UnityLogger;
    AWSConfigs.LoggingConfig.LogResponses = ResponseLoggingOption.Always;
    AWSConfigs.LoggingConfig.LogMetrics = true;

    IAmazonS3 client = new AmazonS3Client(AccessKey, SecretKey, RegionEndpoint.USEast1);
    }


    void SubmitPlayerData(string fileName)
    {
    FileStream stream = null;
    try
    {

    stream = new FileStream(sUserDataPath, FileMode.Open, FileAccess.Read, FileShare.Read);

    var request = new PutObjectRequest()
    {
    BucketName = BucketName,
    Key = fileName,
    InputStream = stream,
    CannedACL = S3CannedACL.Private,
    };

    client.PutObjectAsync(request, (responseObject) =>
    {

    if (responseObject.Exception == null)
    {
    UnityEngine.Debug.Log("successfully uploaded file.");
    }
    else
    {
    UnityEngine.Debug.Log("Error: " + responseObject.Exception);
    }
    stream.Close();
    });
    }
    catch (Exception ex)
    {
    UnityEngine.Debug.Log(string.Format("Error Msg: {0}\nStackTrace: {1}.", ex.Message, ex.StackTrace));
    }
    stream.Close();
    }

    }


    Link.xml file: (/assets/link.xml
    ================================================================

    <linker>
    <!-- if you are using AWSConfigs.HttpClient.UnityWebRequest option-->
    <assembly fullname="UnityEngine">
    <type fullname="UnityEngine.Networking.UnityWebRequest" preserve="all" />
    <type fullname="UnityEngine.Networking.UploadHandlerRaw" preserve="all" />
    <type fullname="UnityEngine.Networking.UploadHandler" preserve="all" />
    <type fullname="UnityEngine.Networking.DownloadHandler" preserve="all" />
    <type fullname="UnityEngine.Networking.DownloadHandlerBuffer" preserve="all" />
    </assembly>
    <assembly fullname="mscorlib">
    <namespace fullname="System.Security.Cryptography" preserve="all" />
    </assembly>
    <assembly fullname="System">
    <namespace fullname="System.Security.Cryptography" preserve="all" />
    </assembly>
    <assembly fullname="AWSSDK.Core">
    <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
    </assembly>
    <assembly fullname="AWSSDK.CognitoIdentity">
    <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
    </assembly>
    <assembly fullname="AWSSDK.CognitoSync">
    <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
    </assembly>
    <assembly fullname="AWSSDK.SecurityToken">
    <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
    </assembly>
    <assembly fullname="AWSSDK.S3" preserve="all"/>
    </linker>

    ================================================================


    awsconfig.xml (located in /Assets/Resources/awsconfig.xml)
    ================================================================
    <?xml version="1.0" encoding="utf-8"?>
    <aws region="us-east-1" correctForClockSkew="true">
    <logging logTo="UnityLogger" logResponses="Always" logMetrics="true" logMetricsFormat="JSON" />
    <s3 useSignatureVersion4="true" />
    </aws>
    ================================================================


    I've confirmed the user has all permissions required. The Access Key & Secret Access Key for said user have been reset and re-etentered.
    The bucket is made for the right region.
    I even changed the bucket permissions to open access to see if it was that.

    I tried initialising the s3client the way it was done in the documentation examples:
    client = new AmazonS3Client(credentials, RegionEndpoint.USEast1);
    this also didn't help.
    I also tried the root user credentials to no avail.
    I downloaded the latest updates of the SDKs and updated them, still no joy.

    I'm truly at a loss here, any assistance would be greatly appreciated.
    I'm hoping there is something I'm missing







     
  2. JokaerStudios

    JokaerStudios

    Joined:
    Jan 29, 2018
    Posts:
    1
    I've run into this issue as well. Did you figure out what happened?

    So far, the best solution for this is to revert to Unity 2017.2.1.
     
    Last edited: Feb 4, 2018
  3. zeen0

    zeen0

    Joined:
    Nov 27, 2017
    Posts:
    6

    Did this actually work? I'm running into the same problem
     
  4. zeen0

    zeen0

    Joined:
    Nov 27, 2017
    Posts:
    6
    THIS WORKED! THANK YOU SO MUCH. LIFE SAVER
     
  5. PrimordialArtStudios

    PrimordialArtStudios

    Joined:
    May 10, 2013
    Posts:
    2
    I ended up using DynamoDB, which turned out to be better suited to my needs. Had it up and running with very little effort, so the issue definitely seems to be with the S3 Unity plugin.
     
  6. tmknr

    tmknr

    Joined:
    Jan 27, 2015
    Posts:
    3
    Same here.
     
  7. tmknr

    tmknr

    Joined:
    Jan 27, 2015
    Posts:
    3
  8. tmknr

    tmknr

    Joined:
    Jan 27, 2015
    Posts:
    3
    Hi all, quick update.
    It works with Unity 2017.4.1f1 and the latest AWS SDK.