Async handler doesn't work on node 8.10
See original GitHub issueI have reduced my project to that snippet which generates an error using the new 8.10:
import awsServerlessExpress from 'aws-serverless-express'
import express from 'express'
export default async (event, context, callback) => {
const app = express()
app.get('/', function(req, res){
res.send('hello world')
})
const server = awsServerlessExpress.createServer(app)
return awsServerlessExpress.proxy(server, event, context)
}
Babel compilation targets node 8.10 to be sure it doesn’t convert async/await to native js code.
Cloudwatch reports:
START RequestId: 3cb224ae-3810-11e8-ba0f-437e442fcf6a Version: $LATEST
Unable to stringify response body as json: Converting circular structure to JSON: TypeError
END RequestId: 3cb224ae-3810-11e8-ba0f-437e442fcf6a
REPORT RequestId: 3cb224ae-3810-11e8-ba0f-437e442fcf6a Duration: 30027.56 ms Billed Duration: 30000 ms Memory Size: 512 MB Max Memory Used: 31 MB
Removing the async
in the handler fix the problem. But my whole project does some await
in the handler which requires the handler to be async.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:37
Top Results From Across the Web
Async handler doesn't work on node 8.10 · Issue #134 - GitHub
Removing the async in the handler fix the problem. But my whole project does some await in the handler which requires the handler...
Read more >async / await breaks my Webpack build for AWS Lambda; how ...
The newly installed babel-runtime is a module that needs to be bundled in the build in order for Lambda to run correctly. Understanding...
Read more >Avoiding the pitfalls of async Node.js functions in AWS Lambda
js 8.10 runtime in AWS Lambda, we have been able to enjoy the benefits of Promises using the async/await syntax and write classy,...
Read more >Common Node8 mistakes in Lambda - Serverless Framework
Here are some common mistakes people make when authoring Lambda functions with Node.js 8.10.
Read more >Node.js 8.10 runtime now available in AWS Lambda
The Lambda programming model for Node.js 8.10 now supports defining a function handler using the async/await pattern.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
PR for this here https://github.com/awslabs/aws-serverless-express/pull/173. Note that I plan on improving the interface in a future breaking change (aws-serverless-express 4.0.0), but for now this is a backwards compatible change with the following interface:
module.exports = awsServerlessExpress.proxy(server, event, context, 'PROMISE').promise
should work