Reputation: 97
I am using AWS web console. I am trying to create lambda function to run my AppSync GraphQL API mutation query. I have seen many answers on web but they all are trying to create lambda on local machine first and then pushing it to AWS cloud. I can't follow this method. I am working directly on AWS web console.
Basically I have a dynamodb database table behind the appsync graphql API. I want to update an entry in dynamoDB using lambda function. To update this entry (in DynamoDB) I need to run a mutation query on appsync graphql API. I want to achieve this using lambda function. I want to call mutation query (of appsync) from lambda.
See the lambda's node.js
code below:
const appsync = require('aws-appsync');
const gql = require('graphql-tag');
require('cross-fetch/polyfill');
const graphqlClient = new appsync.AWSAppSyncClient({
url: 'APPSYNC_ENDPOINT_URL',
region: process.env.AWS_REGION,
auth: {
type: 'AWS_IAM',
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
sessionToken: process.env.AWS_SESSION_TOKEN
}
},
disableOffline: true
});
const mutation = gql`mutation Test($value: String!) {
test(value: $value)
}`;
await graphqlClient.mutate({
mutation,
variables: {
value: 'test'
}
});
I am getting error :
"errorMessage": "Cannot find module 'aws-appsync'"
The lambda function is trying to use aws-appsync
but is unable to find it. How do I 'install' this package on the AWS lambda web console? I am not using my local development machine. I am writing lambda function directly on web console.
How do I enable aws-appsync
package in lambda using only the web console ?
Upvotes: 0
Views: 1020
Reputation: 67
I don't think you can. You could develop the lambda in local environment, add package.json with the dependencies zip the function and node_modules and then upload.
Deploy Node.js Lambda functions with .zip file archives
Upvotes: 1