Last active
January 29, 2021 18:08
-
-
Save numeroSette/72ded50ccd0825d54b1a587eed77ab6d to your computer and use it in GitHub Desktop.
Testing promisse JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as AWS from 'aws-sdk' | |
AWS.config.update({ region: 'us-east-1' }); | |
var credentials = new AWS.SharedIniFileCredentials({ profile: 'default' }); | |
AWS.config.credentials = credentials; | |
const ec2 = new AWS.EC2(); | |
var params = {}; | |
ec2.describeVpcs(params).promise() | |
.then( | |
(data) => { | |
return data; | |
}) | |
.then((data)=>{ | |
return callbackFirst(data); | |
}).then((data)=>{ | |
callbackSecond(data); | |
}) | |
.catch((error) => { | |
console.log(error); | |
}).finally(() => { | |
console.log('finally') | |
}); | |
function callbackFirst(data:any) { | |
let vpcs = []; | |
for (const key in data.Vpcs) { | |
if (Object.prototype.hasOwnProperty.call(data.Vpcs, key)) { | |
const element = data.Vpcs[key]['VpcId']; | |
if(Object.prototype.hasOwnProperty.call(data.Vpcs[key], 'VpcId')){ | |
vpcs.push(element); | |
} | |
} | |
} | |
console.log(vpcs); | |
var params = { | |
Filters: [ | |
{ | |
Name: 'vpc-id', | |
Values: vpcs | |
}, | |
/* more items */ | |
] | |
}; | |
ec2.describeNetworkInterfaces(params).promise().then((data)=>{ | |
console.log(data); | |
}, | |
(error)=>{ | |
return error; | |
}) | |
} | |
function callbackSecond(data:any) { | |
console.log('callbackSecond') | |
console.log(data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment