AWS AppSync 上的 GraphQL 查询后 AWS Lambda 超时
AWS Lambda timeout after GraphQL query on AWS AppSync
我按照本教程使用 Amplify 部署了 AWS AppSync GraphQL 终端节点:
https://aws-amplify.github.io/docs/js/api#amplify-graphql-client
我使用 Node.js 和 TypeScript 创建了一个 Lambda 函数来查询数据:
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);
}
现在,当我通过 HTTP 调用 Lambda 函数时,它会检索数据并将其记录到控制台。但它永远不会完成请求和响应,它总是会遇到超时,即使我将超时增加到 30 秒也是如此。 运行 突变和插入数据也是如此。
有什么想法是错误的吗?
这里的问题是您混合了 lambda 签名。
或者你使用async
和return(或者throw 如果出现错误):
export const list: Handler = async (event: APIGatewayEvent, context: Context, cb: Callback) => {
// ... rest of function
return response;
}
或者你没有使用async
而你使用了callback
函数:
export const list: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
// ... rest of function
cb(null, response);
}
我按照本教程使用 Amplify 部署了 AWS AppSync GraphQL 终端节点:
https://aws-amplify.github.io/docs/js/api#amplify-graphql-client
我使用 Node.js 和 TypeScript 创建了一个 Lambda 函数来查询数据:
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);
}
现在,当我通过 HTTP 调用 Lambda 函数时,它会检索数据并将其记录到控制台。但它永远不会完成请求和响应,它总是会遇到超时,即使我将超时增加到 30 秒也是如此。 运行 突变和插入数据也是如此。
有什么想法是错误的吗?
这里的问题是您混合了 lambda 签名。
或者你使用async
和return(或者throw 如果出现错误):
export const list: Handler = async (event: APIGatewayEvent, context: Context, cb: Callback) => {
// ... rest of function
return response;
}
或者你没有使用async
而你使用了callback
函数:
export const list: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
// ... rest of function
cb(null, response);
}