How To Connect to S3 in Unity

Let’s say you want to upload a file to AWS S3 from your Unity game. Well, if you follow the AWS instructions, you’ll probably run into errors. This guide helps you through the errors I encountered.

Step 1 – Follow the Setup the AWS SDK Tutorial


While importing the AWS SDK into Unity, since I only needed to use S3 for now, I imported the S3 and IdentityManagement package.

Fixing awsconfig.xml

The awsconfig.xml file in the documentation as of Sept 2018 doesn’t work. Use this for your Assets/Resources/awsconfig.xml file (Download here) (Note the region I work in is us-west-2, yours may be different):

<?xml version="1.0" encoding="utf-8"?>
<aws region="us-west-2" correctForClockSkew="true">
    <logging logTo="UnityLogger"
             logMetricsFormat="JSON" />

Errors the above file fixed for me:

  • correctForClockSkew fixes: NullReferenceException: Object reference not set to an instance of an object Amazon.AWSConfigs.GetSection[AWSSection] (System.String sectionName)
  • XmlException: expected ‘>’ (3E) but found ‘<‘ (3C)
  • XmlException: a name did not start with a legal character 60 (<)
  • XmlException: XML declaration cannot appear in this state.

Step 2 – Get the Examples/S3Example.scene working

Follow the Examples/readme.txt. This gives you instructions on setting up an AWS Cognito Pool and setting the region, bucket name, and pool Id in the scene.

Fix the link.xml file

Warning: Rather than follow the link in step 5 [Unity SDK readme], use my link.xml The link listed in the readme has bugs in the xml files (including link.xml being incomplete and awsconfig.xml having compiler errors).

Fix the S3Example.cs code

The original file from the project was littered with bugs when I ran it:

  • HttpErrorResponseException in Post Object (fix by adding region to request)
  • NullPointerException when trying to log responses (fix by logging exception rather than http codes)
  • “InvalidOperationException: Cannot override system-specified headers” (fix by using AWSConfigs.HttpClientOption.UnityWebRequest http client)

Here’s my S3Example.cs that fixes the above.

Make your IAM and S3 permissions correct and secure

Don’t make your S3 bucket public.

I wanted to limit my Cognito roles to only access have write access to objects in my bucket (not the whole bucket), read access to my bucket, and list actions.

Here’s the managed IAM policy I created to add to my Cognito roles (Note: Change BUCKET_NAME in the resources section to your bucket twice!!!):

    "Version": "2012-10-17",
    "Statement": [
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
            "Resource": [
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": [
            "Resource": "*"

Hope this helps you!

Follow me in social media:
Share this post:

Comments 6

  • Thanks for sharing, really painful process until I found your post!

  • hi,
    Thank you for detailing the process. it really makes things easy but I do have a question.
    I’m stuck at the point of adding fix using this line
    “AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;”.

    The issue is that somehow unity is giving me error that `Amazon.AWSConfigs’ does not contain a definition for `HttpClient’.
    The same goes for ‘HttpClientOption’. somehow ‘AWSConfigs’ is missing these entries.

    Anything you could say about it?

    • Usually errors like this are caused by spelling mistakes and typos. I wonder if you are using an IDE that’s supports auto fill if AWSConfigs has other definitions in it or if you could auto complete the http client?

      Please let me know what works for you.

  • Is this still valid as of Dec 2019? I followed your steps and when I click “List Buckets” this is the first error I get:

    HttpErrorResponseException: Exception of type ‘Amazon.Runtime.Internal.HttpErrorResponseException’ was thrown.
    Amazon.Runtime.Internal.UnityRequest.EndGetResponse (IAsyncResult asyncResult)
    Amazon.Runtime.Internal.HttpHandler`1[System.String].GetResponseCallbackHelper (System.Object state)
    Amazon.Runtime.Internal.Util.UnityDebugLogger:Error(Exception, String, Object[])
    Amazon.Runtime.Internal.Util.Logger:Error(Exception, String, Object[])
    Amazon.Runtime.Internal.ErrorHandler:ProcessException(IExecutionContext, Exception)

Leave a Reply

Your email address will not be published.