Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

899
Visualizações
"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:

exports.getSong = (event, context, callback) => { }

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

exports.getSong = async (event, context) => { }

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

{
  "errorType": "Runtime.UserCodeSyntaxError",
  "errorMessage": "SyntaxError: Unexpected token '.'",
  "trace": [
    "Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '.'",
    "    at _loadUserApp (/var/runtime/UserFunction.js:98:13)",
    "    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
    "    at Object.<anonymous> (/var/runtime/index.js:43:30)",
    "    at Module._compile (internal/modules/cjs/loader.js:1133:30)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)",
    "    at Module.load (internal/modules/cjs/loader.js:977:32)",
    "    at Function.Module._load (internal/modules/cjs/loader.js:877:14)",
    "    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)",
    "    at internal/main/run_main_module.js:18:47"
  ]
}

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:

var anotherAsyncFunction = async () => { }
exports.getSong = (event, context, callback) => { anotherAsyncFunction() }
    

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.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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 :

export const getSong = async (event, context) => { ...}

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

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda