3
votes

I have a React app setup with AWS Amplify. The initial purpose of the app is to act as a portal for AWS Appstream. Users can login and kick off a streaming instance via the Appstream api.

The part that generates the streaming url is a Lambda function. Currently, this is called directly from the app via the AWS sdk (the IAM context is materialised via Cognito). However, the portal will grow in functionality and I'm likely to need an api. For this, I'm thinking of using AppSync/GraphQL.

But I was wondering if I could simplify coding patterns in the app by using GraphQL exclusively. That is, can I use GraphQL/AppSync to make a call to the Lambda function that I've created? There's a couple of reasons why I'd like to do this:

  1. My main goal is to reduce Amplify to a common protocol (in this case GraphQL). This means that I can create a version of the portal that runs on-premises. It also helps support another goal I have - by using GraphQL it could make changing cloud providers possible (without re-writing everything)

  2. I'd like to prototype the app in Elm - to see if coding against Amplify would be practical. With Elm there are no AWS/Amplify libraries. But there is a GraphQL library. This could provide a means to reduce interop

  3. I could add a Rest api for the Lambda call, but it would be nice to keep api access to one method

Sorry if this is a naive question - I'm currently learning AppSync/GraphQL, Lambda and Amplify.

Looking at AppSync itself, it seems that I could create an object called Fleet and make streamingUrl a property that GetFleet() returns. I could then attach a resolver to the Lambda function for this property. However, there seems no obvious way to configure this via Amplify. I have successfully re-created my Lambda function via amplify function add, which is nice.

Is there a way to automate this via Amplify? Maybe it's a matter of creating my own GraphQL Transform? Or is there something in Amplify to do this already and I'm just not seeing it?

2

2 Answers

2
votes

UPDATE:

It seems like this is now possible with AppSync. You can read more about it here and here

ORIGINAL ANSWER:

In response to the part of the question about calling the Lambda via GraphQL:

I think that this is possible right now with AppSync but not with Amplify.

Using the AppSync console will allow you to create a Lambda resolver - Amplify currently does not support this. When you publish from Amplify your resolver will be overwritten.

It appears that this issue is being worked on:

https://github.com/aws-amplify/amplify-cli/issues/74

https://github.com/aws-amplify/amplify-cli/issues/83