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.

Async handler doesn't work on node 8.10

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:13
  • Comments:37

github_iconTop GitHub Comments

16reactions
brettstackcommented, Jul 16, 2019

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:

exports.handler = async (event, context) => awsServerlessExpress.proxy(server, event, context, 'PROMISE').promise
12reactions
brettstackcommented, May 23, 2019

module.exports = awsServerlessExpress.proxy(server, event, context, 'PROMISE').promise should work

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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