Getting Started with AWS in Unity
One part of publishing applications in Unity is working with 3rd party services. One of the biggest and most popular today is Amazons web services, and we can take advantage of much of what they have to offer for free!
First of all, I don’t have the link on me, but thankfully we have google to help us so we can just search for “Set up mobile SDK for Unity”
We’ll be given the first few steps in our first result, so let’s just click on it.
We’re given a set of prerequisites that we need to follow. The first thing,of course, is to set up an AWS account. It’s pretty straightforward so we’ll move on to the next step.
After signing up and signing in, we’ll be presented with this dashboard. There’s a lot to take in, but thankfully we don’t need to deal with it for now, we just need to go back to the prerequisites list.
Step 1 is really easy. Download the zipfile, open a unity project and import the package.
I went ahead and downloaded the file into its own folder, and then unzipped it. It created a new folder with all the installable packages.
Putting it into list view gives us a more readable set of files that include Cognito Sync, Dynamo, Identity Management, Kineses, and other various services. We’re concerned with the S3 service, so it looks like AWSSDK.S3.3.113.2.unitypackage is the one to install!
The easiest way to install the package is to just drag the file on top of Unity and Unity will take care of the rest. Just click on Install when you see the assets window appears.
After installation, we’ll have various folders, the AWSSDK which contains all the necessary dlls to communicate with amazon web services, an example folder, and a plugins folder for android integration.
Looking at the example scene, we can see some examples of buttons that access to get and post to amazons s3 servers.
We’ll also be referring to the example script to see how it accesses amazons services and integrate those methods into our code:
For now, let’s go back to our example scene and organize our AWS folder a little more by creating a new folder named whatever you want, but AWS seems to be the most descriptive.
Referring back to the webpage, the next step is to configure the SDK for Unity:
As stated in the page, in either the Start or Awake method of your applications script, include the line “UnityInitializer.AttachToGameObject(this.gameObject);” to initialize Amazon AWS. We can skip to step 3 after this.
But getting back to actually implementing the steps, I’ll create a new folder in the insurance app project and create a new script called AWSManager.
I’ll also create an empty to attach it to and then write the initialization code. We need to use “using Amazon;” at the header.
If all is successful, Amazon will create some new components for our manager and we’ll be ready for the next step, sharing our identity with amazon and getting an identity pool.
Great! Everything works. The final step is to get an identity pool using cognito. This apparently allows us to access amazon services without sharing our own private login info which I’m assuming is for cases like someone reverse-engineering the apk and obtaining the info.
First, I’ll right click on the amazon cognito console link to log in.
We then want to manage identity pools
We’ll identify our pool as Service Adjustment App, and enable access to unauthenticated identities since nobody really needs to log in to the app. we’de choose the other options if we had user logins.
The next screen will tell you it will create an authenticated and unauthenticated IAM Roles to access cognito, go ahead and just click on allow.
We’re then taken to the final screen where the identity pool is created!
I went ahead and copy/pasted the code into a text file. I have a feeling we’re going to need it later. But that’s our general introduction to Amazons AWS! No doubt we’ll get more into it as we develop our apps!