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

89
Visualizações
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 Respostas
Responde à pergunta

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