Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

88
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!