“Runtime.UserCodeSyntaxError” while trying to declare an async AWS Lambda function


I’ve had an old AWS Lambda function, that was declared as synchronous (used Promises), the declaration looked like this:

It worked as intended. Recently, I decided to re-write it using async/await and thus, tried declaring the getSong function asynchronously, like so:

And while trying to execute, I get the following error in it’s entirety:

It absolutely not clear what the issue is from this error message, but by googling for similar issues and narrowing everything down, I figured out that the problem is the function declaration.

I tried declaring the getSong function as synchronous, and then running another asynchronous function inside it, like so:

But then, I get the same error. So clearly, it has something to do with the Asynchronous function declaration inside the Lambda. What might be the issue here? Thank you.


I encounter a similar issue. for me it was res.Body?.toString('utf-8') which lambda could not understand what is Body?. i think in your case you should do the following :

also for whoever has the same problem, the best way to figure out the reason is to go to your lambda code page, it should show a red X on the line of code

Leave a Reply