How to get started with AWS S3 cloud storage for Unity

Niklas Bergstrand
4 min readAug 26, 2021

--

Let’s go over how to get started with AWS cloud storage for Unity.

First, go to https://aws.amazon.com and create an account:

Download the AWS SDK package from https://docs.aws.amazon.com/mobile/sdkforunity/developerguide/setup-unity.html:

Open up Unity and import the S3 package:

Open up your web browser again and on the AWS website navigate to Amazon Cognito. Click on Manage Identity Pools:

Enter a name for the identity pool and tick “Enable access to unauthenticated identities”

Click on allow:

Go to S3 Buckets:

Click on create bucket:

Enter a unique name for the bucket:

Scroll down and click on Create bucket:

Go to IAM and create a policy:

Set service of the policy to S3 and allow all actions:

Name the policy and then click on create policy:

On the IAM main page click on roles and then click on the unauthenticated role:

Make note of the Role ARN and attach the new policy created:

Go back to S3 and select the bucket:

Click on the permissions tab:

Click on Edit bucket policy:

Click on Policy Generator:

AWS Policy Generator:
- Set Policy to S3 Bucket Policy.
- Set Effect to Allow.
- In the principal field add the Role ARN.
- Allow All Actions
- In the ARN field enter the following text “arn:aws:s3:::BUCKETNAME/*”
i.e arn:aws:s3:::aws-insurance-app-bucket/*

Click Add Statement and then Generate Policy:

Copy the JSON text:

Add the text to the bucket policy and save:

Go back to Unity and create a script called AWSManager. Create a new game object and attach the script:

Open up the AWSManager script and copy over the using directives from the S3Example script that came with the S3 package. Turn the AWSManager class into a singelton:

Create the two properties needed RegionEndpoint and AmazonS3Client. You get the details that belongs to your app from the sample code on Amazon Cognito:

Lastly, in the Awake function initialise by calling UnityInitialiser.AttachToGameObject. Set AWSConfigs.HttpClient to UnityWebRequest and then list all the buckets for this app:

If all is correct you will get this output in the console window when you press play:

Good luck!

--

--

Niklas Bergstrand
Niklas Bergstrand

Responses (1)