Last active
July 23, 2019 06:17
-
-
Save ottokruse/d0c15adb85c0214267a7e5027cb15fd0 to your computer and use it in GitHub Desktop.
Example AWS Lambda function that executes AWS AppSync GraphQL Mutation using AWS Amplify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Amplify = require('aws-amplify'); | |
Amplify.default.configure({ | |
aws_appsync_graphqlEndpoint: 'https://something.appsync-api.eu-west-1.amazonaws.com/graphql', | |
aws_appsync_region: 'eu-west-1', | |
aws_appsync_authenticationType: 'API_KEY', | |
aws_appsync_apiKey: 'yourkey' | |
}); | |
const mutation = `mutation CreatePerson($firstName: String!, $lastName: String!, bankAccountBalance: Float!) { | |
createPerson(firstName: $firstName, lastName: $lastName, bankAccountBalance: $bankAccountBalance) { | |
firstName | |
} | |
}`; | |
exports.handler = async (event) => { | |
// Let's assume that the incoming event will at least have the following fields (and maybe more): | |
// { firstName: 'Edsger', lastName: 'Dijkstra', bankAccountBalance: 0.0 } | |
await Amplify.API.graphql(Amplify.graphqlOperation(mutation, event)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure how that works with the environment variables. But if you get aws-exports.js in your Lambda bundle from an Amplify build you can just read that.