Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automate Lambda resolver for AppSync using Amplify?

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?

like image 865
Mitkins Avatar asked Feb 06 '26 23:02

Mitkins


1 Answers

Yes, you can do this on Amplify.

Docs

Amplify: https://aws-amplify.github.io/docs/cli-toolchain/graphql#function

AWS AppSync (worth reading also for useful general guidance): https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html

Example:

Walkthrough + Code Repo:

  • https://dev.to/dabit3/lambda-function-graphql-resolvers-11cd
  • https://github.com/dabit3/lambda-graphql-resolver-examples
like image 71
Ville Avatar answered Feb 09 '26 08:02

Ville



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!