Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
return Promise when invoking Lambda function

I'm trying to invoke a Lambda function and return a Promise on finish,

but i get the following error:

"createUser(...).then is not a function"

const createUser = (phone) => {
  return lambda.invoke({
    FunctionName: 'createUser',
    Payload: JSON.stringify({"phone": phone})
  }, (err, data) => {
    let payload = JSON.parse(data.Payload);

    if (payload.statusCode != 200) {
      Promise.reject(payload);
    }
    Promise.resolve(payload);
  })
}

createUser('')
  .then(res => console.log(res))
  .catch(err => console.log(err))

Already tried declaring a new Promise using the

let promise = new Promise((resolve, reject) => {...})

but that didn't work also...

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

aws-sdk supports promises through a promise() property on the object returned from most API methods, like so:

const createUser = (phone) => {
    return lambda.invoke({
        FunctionName: 'createUser',
        Payload: JSON.stringify({"phone": phone})
    }).promise();
}

createUser('555...')
.then(res => console.log)
.catch(err => console.log);

https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/using-promises.html

over 4 years ago · Santiago Trujillo Denunciar

0

Alright,figured it out...

I haven't returned the promise correctly.

to fix the error, I have declared the lambda.invoke inside of a new Promise, and then returned the Promise like this:

const createUser = (phone) => {
   let promise = new Promise((resolve, reject) => {
    lambda.invoke({
      FunctionName: 'createUser',
      Payload: JSON.stringify({"phone": phone})
    }, (err, data) => {
      let payload = JSON.parse(data.Payload);
      if (payload.statusCode != 200) {
        reject(payload);
      } else {
        resolve(payload);
      }
    })
  })
  return promise;
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda