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

90
Vistas
aws-sdk-js E2 createVPC is executed twice while waiting adding a promise
    ec2
      .createVpc(params, function (err, data) {
        if (err) {
          console.log(err, err.stack);
          // an error occurred
        } else {
          logger.log.info(
            `Deployment VPC ${deployment.name} has been created.`
          );
          db.saveData(data, deployment.name);

          return data;
        }
      })
      .promise()

I was trying to run this code above, which is the most simplest resource in the docs. But when I added .promise() the create operation was triggered twice. When I remove it, it creates only one instance of VPC. But I need to access the information about the created resource in order to save it to the database.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I would guess that this happens because you mix two ways of triggering a request - providing a callback and calling a promise. If you want to use promises, you should process the returned data in then() (or use await).

Example with then():

ec2.createVpc(params).promise().then((data) => {
    logger.log.info(
       `Deployment VPC ${deployment.name} has been created.`
    );
    db.saveData(data, deployment.name);
    return data;
}, (err) => {
    console.log(err, err.stack);
})
about 4 years ago · Juan Pablo Isaza 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