I deployed an AWS AppSync GraphQL endpoint with Amplify following this tutorial:
https://aws-amplify.github.io/docs/js/api#amplify-graphql-client
I created a Lambda function with Node.js and TypeScript to query data the data:
import { APIGatewayEvent, Callback, Context, Handler } from 'aws-lambda';
import Amplify, { API, graphqlOperation } from "aws-amplify";
import * as queries from './src/graphql/queries';
import * as mutations from './src/graphql/mutations';
import { CreateBlogInput } from './src/API';
import aws_config from "./src/aws-exports";
Amplify.configure(aws_config);
export const list: Handler = async (event: APIGatewayEvent, context: Context, cb: Callback) => {
const allBlogs = await API.graphql(graphqlOperation(queries.listBlogs));
// this seems to be working
console.log(JSON.stringify(allBlogs));
const response = {
statusCode: 200,
body: JSON.stringify(allBlogs),
};
cb(null, response);
}
Now, when I call the Lambda function via HTTP, it retrieves the data and logs it to the console. But it never finishes the request and responds, it always runs into a timeout, even if I increase the timeout to 30 seconds. The same happens for running a mutation and inserting data.
Any ideas what could be wrong?
The problem here is that you're mixing your lambda signatures.
Either you use async
and return (or throw in case of an error):
export const list: Handler = async (event: APIGatewayEvent, context: Context, cb: Callback) => {
// ... rest of function
return response;
}
Or you do not use async
and you use the callback
function:
export const list: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
// ... rest of function
cb(null, response);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.