Run amplify add function and go thru the manual configuration and add access to other resources. Add API here.
Run amplify update api if you have a project already setup and configure IAM as an additional auth mode.
Add the authorization as following to your type definition:
type Something
@model
@auth(
rules: [
{ allow: private, provider: iam }
]
) {
id: ID!
something: String
}
This allows Lambda to fetch from this type.
- Open the terminal in the
amplify/backend/function/(nameOfYourFunction)/srcdirectory in your newly created Lambda function. - Run
npm install appsync-client graphql-tag
Change the code as you find in this gist's JavaScript file.
When you are done setting up your Lambda function to your desired result run amplify push to push your Lambda function to the AWS Cloud.


This is a nice guide for sure. I myself was stuck figuring this out at some point. While my original solution did include using
aws-appsyncI quickly moved away from it because of all the dependencies it pulls. It adds ~10MB to your Lambda functions.It might not be the easiest to understand but the solution from the official documentation is probably the lightest solution. Mostly because it uses node built-in libraries and the
aws-sdkthat is available in the Lambda environment so it does not have to be bundled in your function.My current solution is a variation of the official example. I use a
fetchpolyfill instead ofhttpsdirectly but honestly, you can probably adapt the example for your favorite HTTP client. Here is my simple functionI did not know packages like appsync-client, aws4 and aws4fetch exist. If I run into problems with my current solution I will probably try one of these libs.