question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AWS Lambda with API Gateway throwing response error

See original GitHub issue

I’m experiencing the same issue outlined in this closed issue. I’m connecting to the lambda via API Gateway and it works fine if I do something like this:

exports.fulfillment = function (event: any, context: any, callback: any) {
    app.handler(event, {}).then((res) => {
        if (res.status !== 200) {
            callback(null, { fulfillmentText: `I got status code: ${res.status}` });
        } else {
            callback(null, res.body);
        }
    }).catch((e) => {
        callback(null, { fulfillmentText: `There was an error\n${e}` });
    });
};

I would love to be able to do it the way your documentation outlines, but if I do I get a TypeError:

{
    "errorMessage": "Cannot convert undefined or null to object",
    "errorType": "TypeError",
    "stackTrace": [
        "Function.keys (<anonymous>)",
        "Lambda.<anonymous> (/var/task/node_modules/actions-on-google/dist/framework/lambda.js:36:36)",
        "Generator.next (<anonymous>)",
        "/var/task/node_modules/actions-on-google/dist/framework/lambda.js:22:71",
        "new Promise (<anonymous>)",
        "__awaiter (/var/task/node_modules/actions-on-google/dist/framework/lambda.js:18:12)",
        "/var/task/node_modules/actions-on-google/dist/framework/lambda.js:30:46",
        "omni (/var/task/node_modules/actions-on-google/dist/assistant.js:44:53)"
    ]
}

I guess the ask in this issue is either:

  • get this working the way it is outlined in the docs exports.fulfillment = app;.
  • Update the docs to match the need for a lmbda wrapping function like I have above.

If I’m missing something in my Lambda or API Gateway config I’d be fine with changing/updating it. Just let me know!

Thanks, Tommy

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:24 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
igilhamcommented, Sep 7, 2018

I’m seeing the same issue but haven’t had time to look into a fix yet. I’ll have to check the proxy integration setting.

Ultimately, I think we just need better documentation for how to run Actions on Google projects on AWS Lambda correctly.

1reaction
Canaincommented, Feb 20, 2019

With the release of 2.6.0 through df48d7e1ac9a3172f2f7c3ec76c5767165c098a2, we added support to detect and parse different request formats from lambda.

Add support for other lambda formats

* Support for lambda entire body input format
* Support for lambda input body being an object

The response format is still the same as before. For now the way to perform custom response logic is still to manually call app.handler with your own code logic. But now the library will be able to handle most request formats on its own.

Let us know if there are any issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle Lambda errors in API Gateway - AWS Documentation
For Lambda custom integrations, you must map errors returned by Lambda in the integration response to standard HTTP error responses for your clients....
Read more >
How to handle Lambda errors in API Gateway - Fathom
Navigate to API Gateway. · Click Create API · Select HTTP API · Click Add Integration under the Integrations section · Choose an...
Read more >
Error Handling in AWS Lambda and API Gateway - Medium
Lastly, if an error is thrown without one of the mapped status codes then the API Gateway will return a 504 Bad Gateway...
Read more >
AWS: Passing errors from Lambda to API Gateway
Throwing an error generates the “errorMessage” object key in the Lambda response, which we then configure API Gateway to look for below.
Read more >
Fix the Most Common API Gateway Request Errors - Dashbird
AWS API Gateway is an HTTP gateway, and as such, it uses the well-known HTTP status codes to convey its errors to you....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found