Configure And Deploy A Unity Game To Amazon S3

Amazon Simple Storage Service (Amazon S3) is an object storage service by AWS that can be used to store all kind of data, files, and objects. While S3 is majorly used to store data and files, you can also store/host applications. The typical way to host a website in S3 is hosting static websites. Key benefits of hosting static websites in S3 includes high performance and scalability, cost effective, built-in security, compliance, and audit capabilities, integrated access controls, and analytics. And the best part is, it just takes minutes to setup, deploy, and launch your website in S3.
 
When you build a static Unity web app or game that is built to be run in a browser, you can use Amazon S3. This step by step tutorial explains how to configure a S3 bucket, upload files, and host a static website in S3.
 
Please follow the following steps.
 
Step 1. Create a S3 bucket
 
Login to your AWS account and go to AWS Management Console.
  1. Navigate to S3 in the AWS Console
    Find S3 by typing S3 in the services text box and select S3, Scalable Storage in the Cloud.

    Configure And Deploy A Unity Game To Amazon S3
  1. Create new bucket
    Click on Create bucket and enter a bucket name. Name does not have capital letters. I give my bucket name, “cscbucket”.

    Configure And Deploy A Unity Game To Amazon S3
Note
A bucket name has to be a unique name. If there is previously bucket in AWS, you will get an error message.
 
Select a Region. I keep my Region as US East.
 
Configure And Deploy A Unity Game To Amazon S3
 
Click Next.
 
This screen is for bucket properties. Set all properties as required by your policies. For simplicity, I keep the default settings.
 
Configure And Deploy A Unity Game To Amazon S3
 
Click Next.
 
On this screen, we can block or allow all public access. We will use Permissions. So leave this default as well. We will come back here later.
 
Configure And Deploy A Unity Game To Amazon S3
 
Click Next.
 
On next screen, you will see selections options etc.
 
Configure And Deploy A Unity Game To Amazon S3
 
Click Create bucket to create the bucket.
 
You will notice “cscbucket” bucket in the bucket list.
 
Configure And Deploy A Unity Game To Amazon S3
 
Step 2. Upload Files to a S3 bucket
 
Now, the next step is to upload our production build project that needs to be deployed in AWS.
 
Click on the bucket name.
 
On this screen, we can upload files/objects and set their properties.
 
Configure And Deploy A Unity Game To Amazon S3
 
Upload all the files to bucket using drag and drop or using the Add Files button.
 
Configure And Deploy A Unity Game To Amazon S3
 
Easiest way is to drag and drop all files including folders to the screen.
 
Configure And Deploy A Unity Game To Amazon S3
 
Click Upload button to upload files.
 
You will see some error message if there are any problems with the file upload.
 
In my case, I see files have been uploaded.
 
Configure And Deploy A Unity Game To Amazon S3
 

Set Bucket Properties and Enable Static Website Hosting

 
Go to your S3 buckets list and click on the bucket name.
 
Click the “Properties” tab.
 
Configure And Deploy A Unity Game To Amazon S3
 
Click the “Static website hosting” option on the above screen.
 
You will get the Static website hosting screen.
 
Configure And Deploy A Unity Game To Amazon S3
 
Select “Use this bucket to host a website”.
 
Enter “index.html” as the Index document. In our case, the index file is Index.html.
 
This can be any default document of your website. You can also set error, redirection, and other settings here. For now, we will leave everything default.
 
Note
As soon as you select this option, you will get an Endpoint created by AWS. That is your URL to access this static website. In the above case, it is
 
Configure And Deploy A Unity Game To Amazon S3
 
Click Save button.
 
You will see Bucket hosting is checked on the Static website hosting box.
 
Configure And Deploy A Unity Game To Amazon S3
 
Now your bucket is configured for static website hosting, and you now have an S3 website URL - http://cscbucket.s3-website-us-east-1.amazonaws.com
 
We are not done yet. This URL still is forbidden to access publicly. We must set access permissions and policies.
 
If you click on the above URL, you will get the following 403 Forbidden error.
 
Configure And Deploy A Unity Game To Amazon S3
 

Grant Access to Website

  • Go back to S3 buckets list and click on your bucket name.
  • Select the “Permissions” tab at the top.
  • Under “Block all public access”, click “Edit” and check/uncheck Block all public access.
Check policies/ACLs based on your company policy and set Group access that should have public access to this bucket.
 
Configure And Deploy A Unity Game To Amazon S3
 
On the above screen, check/uncheck block public access to buckets and objects that are granted through ACLs and access point policies.
 
Configure And Deploy A Unity Game To Amazon S3
 
After Confirm, you will see the “Public access settings updated successfully” message.
 

Update S3 Bucket Policy

 
Click into your bucket.
 
Click the “Permissions” section.
 
Select “Bucket Policy”.
 
Add the following Bucket Policy and then Save
  1. {  
  2.     "Version""2008-10-17",  
  3.     "Id""PolicyForPublicWebsiteContent",  
  4.     "Statement": [  
  5.         {  
  6.             "Sid""PublicReadGetObject",  
  7.             "Effect""Allow",  
  8.             "Principal": {  
  9.                 "AWS""*"  
  10.             },  
  11.             "Action""s3:GetObject",  
  12.             "Resource""arn:aws:s3:::cscbucket/*"  
  13.         }  
  14.     ]  
  15. }  
Configure And Deploy A Unity Game To Amazon S3
 
Change the bucket name with newly created bucket name in the above policy. That is all.
 
Now, the website is available to access publicly.
 
http://cscbucket.s3-website-us-east-1.amazonaws.com
 

Summary

 
In this step by step tutorial, we learned how to configure an AWS S3 bucket and deploy a Unity game to the bucket and configure it to host and run the game in the cloud.


Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.