代码之家  ›  专栏  ›  技术社区  ›  zirkelc

AWS AppSync上GraphQL查询后的AWS Lambda超时

  •  0
  • zirkelc  · 技术社区  · 6 年前

    我在本教程中部署了AWS AppSync GraphQL端点和Amplify:

    https://aws-amplify.github.io/docs/js/api#amplify-graphql-client

    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秒。运行变异和插入数据也会发生同样的情况。

    1 回复  |  直到 6 年前
        1
  •  5
  •   thomasmichaelwallace    6 年前

    这里的问题是你混合了你的lambda签名。

    async 返回

    export const list: Handler = async (event: APIGatewayEvent, context: Context, cb: Callback) => {
      // ... rest of function
    
      return response;
    }
    

    您不使用 你用 callback

    export const list: Handler = (event: APIGatewayEvent, context: Context, cb: Callback) => {
      // ... rest of function
    
      cb(null, response);
    }