0
votes

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?

1
What does your Lambda function look like? From your first console.log statement to the AppSync API via aws-amplify, it seems like it works fine? Moreover, please capture requestIds, response status code, response headers, etc. Did you try to invoke Lambda separately? I'm not sure from your question on what is timing out.Shankar Raju
The posted code is my lambda function. It gets executed until the first console.log and then there's no response. Callback seems to be not invoked.zrkl

1 Answers

5
votes

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);
}