- Home /
How to use AWS AppSync in Unity
I am trying to use AppSync from AWS (https://aws.amazon.com/appsync/) in Unity.
I created a new app with the sample source data (see image below) and I am trying to simply access the data, without any success so far. The Auth Mode for the app is set to API KEY.
In order to add the AppSync library to Unity, I used the extension "NuGet for Unity" from ReCreation Studios, which works perfectly with other AWS libraries like Cognito.
This is my script:
void Start () {
InitAmazonAppSyncClient();
DoMagicWithAppSync();
}
private void DoMagicWithAppSync()
{
var request = new GetDataSourceRequest();
request.ApiId = apiId;
request.Name = "AppSyncEventTable";
amazonAppSyncClient.GetDataSource(request);
}
private void InitAmazonAppSyncClient()
{
AmazonAppSyncConfig config = CreateAmazonAppSyncConfig();
// TODO how do I set the apiKey and the url????
amazonAppSyncClient = new AmazonAppSyncClient(config);
Debug.Log("client instantiated");
}
private AmazonAppSyncConfig CreateAmazonAppSyncConfig()
{
AmazonAppSyncConfig config = new AmazonAppSyncConfig
{
LogResponse = true,
RegionEndpoint = Amazon.RegionEndpoint.EUWest1
};
config.Validate();
Debug.Log("Config validated");
return config;
}
This results in the following exception: AmazonServiceException: Failed to retrieve credentials from EC2 Instance Metadata Service.
I can't seem to find a way to set the apiKey or apiUrl anywhere and their documentation does not seem to help at all. In their android sample project, there's a way to set the apiKey and apiUrl when instantiating the client (https://github.com/aws-samples/aws-mobile-appsync-events-starter-android/blob/master/app/src/main/java/com/amazonaws/demo/appsync/ClientFactory.java), but I did not find a way to do this in Unity. Neither the AmazonAppSyncConfig nor the AmazonAppSyncClient have any fields related to apiKey or apiUrl.
I did find a serviceUrl in the config, but when I change that, I get a 500 Internal Server Error.
There is a class called AWSCredentials, which can be passed in the constructor of the AmazonAppSyncClient, but again, I can't find a way to set anything in the AWSCredentials class.
Any ideas?
Would also like to know if you ever got this working.
Your answer
Follow this Question
Related Questions
Caching AssetBundle downloaded previously without using WWW.LoadFromCacheOrDownload 0 Answers
Accessing X509Store returns zero certificates 0 Answers
Twitter SDK for Unity: Bad Authentication Data, error code 215 2 Answers
I can not get oAuth working on Android App made with Unity3D 0 Answers
Help with Game Center login. 1 Answer