Data Communication with AWS: Part 2- App Dev Series 8
Objective: create a bucket of AWS S3 and linking to it with our app.
We have finished the file sending request in the previous article.
Today we will focus on the setting of AWS S3.
To start using S3 bucket, go to AWS console and search S3.
Select S3 to the page, and click Create Bucket on the top right.
Make a unique name to your bucket and adjust all the settings you need.
After these, you should have a bucket in your list.
Now we need to start using S3 service. We will check the documents of AWS mobile SDK for Unity and follow the steps.
First we need to create a S3 client. Before we follow the steps of guiding documents, it would be better if we using all the namespace from the code example in AWSSDK folder, and paste it into the AWSManager script we created in the previous tutorial.
That way we could prevent any unexpected error in the upcoming setting.
After using all the namespace, we can follow the instruction of guiding documents to create a S3 client.
Copy and paste this line into Awake() method of AWSManager script.
After pasted it, there should be an error since we have not declare the variable yet. If we back to Set up AWS mobile SDK for Unity guiding documentation, there is an example code of using Cognito to obtain the key.
Copy and paste the example code to Awake() and above the line of S3Client.
Ensure and copy your identity pool ID and region, then cover the data of example code.
Following the instruction of guiding documents, next should be list all buckets.
As the previous section, it is also contain an example code of this part.
Copy the code and paste it under creating S3Client line of code.
And as it mentioned in the comment, ResultText is using to display the status, which we will not use it in our code. Delete all the lines with ResultText, and change Client to S3Client.
Because we only got one bucket, we can change the line under the ForEach() method, and just reveal the name of our bucket by using Debug.Log.
Configure the RegionEndpoint
Before we run the app to test if we can receive our bucket name, there is a configuration of RegionEndpoint we need to do.
If you run the app in this way, you should receive the error message like me:
We need to configure the RegionEndpoint, which we can find the reference in the S3Sample script.
Open the script, and locate the RegionEndpoint variables at about line 39.
Copy this part into AWSManager and change the region to the region of your.
Then add the RegionEndpoint to S3Client as the parameter of new S3Client.
Using UnityWebRequest as HttpClient
There is one more adjustment it need to be done. After we run the app, it might shows the error called InvalidOperationalException.
We can fix the error by using the default UnityWebRequest as HttpClient to AWS.
Add one line to Awake() just after the UnityInitializer.
Now your app should run without any error.
That’s all for this article.
We will continue configuring the communication with S3 in the next article.