、例えば
、あなたは、複数で 領域のAmazon EC2オブジェクトにアクセスする各地域のEC2サービスオブジェクトを作成し、それに応じて、各サービスオブジェクトの 領域設定を設定する必要がある場合。
var ec2_regionA = new AWS.EC2({region: 'ap-southeast-2', maxRetries: 15, apiVersion: '2014-10-01'});
var ec2_regionB = new AWS.EC2({region: 'us-east-1', maxRetries: 15, apiVersion: '2014-10-01'});
私の実装、
var AWS = require('aws-sdk');
var EC2Objects = [
new AWS.EC2({apiVersion: '2016-11-15',region: 'us-east-1'}), //N. Virginia
new AWS.EC2({apiVersion: '2016-11-15',region: 'us-east-2'}), //Ohio
new AWS.EC2({apiVersion: '2016-11-15',region: 'us-west-1'}), //N. California
new AWS.EC2({apiVersion: '2016-11-15',region: 'us-west-2'}), //Oregon
new AWS.EC2({apiVersion: '2016-11-15',region: 'ca-central-1'}), //Canada (Central)
new AWS.EC2({apiVersion: '2016-11-15',region: 'eu-west-1'}), //Ireland
new AWS.EC2({apiVersion: '2016-11-15',region: 'eu-central-1'}), //Frankfurt
new AWS.EC2({apiVersion: '2016-11-15',region: 'eu-west-2'}), //London
new AWS.EC2({apiVersion: '2016-11-15',region: 'ap-northeast-1'}), //Tokyo
new AWS.EC2({apiVersion: '2016-11-15',region: 'ap-northeast-2'}), //Seoul
new AWS.EC2({apiVersion: '2016-11-15',region: 'ap-southeast-1'}), //Singapore
new AWS.EC2({apiVersion: '2016-11-15',region: 'ap-southeast-2'}), //Syndney
new AWS.EC2({apiVersion: '2016-11-15',region: 'ap-south-1'}), //Mumbai
new AWS.EC2({apiVersion: '2016-11-15',region: 'sa-east-1'}) //Sao Paulo
];
var instances = [];
listEc2();
function listEc2(){
var params = {};
for(var i=0; i<EC2Objects.length; i++){
EC2Objects[i].describeInstances(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else ec2ListBuilderCallback(data); // successful response
});
}
}
function ec2ListBuilderCallback(data){
instances.push(data);
if(instances.length == EC2Objects.length){
console.log(JSON.stringify(instances));
}
}
OUTPUT:
[{"Reservations":[]},{"Reservations":[{"ReservationId":"r-0e7c0a2e3cf30944c","Groups":[],"Instances":[{"InstanceId":"i-0391f0e44b04675ad","ImageId":"ami-0b33d91d","State":{"Code":16,"Name":"running"}],{"Reservations":[]},{"Reservations":[]},{"Reservations":[]},{"Reservations":[]},{"Reservations":[]},{"Reservations":[]},{"Reservations":[]},{"Reservations":[]},{"Reservations":[]},{"Reservations":[]},{"Reservations":[]},{"Reservations":[]}]
それは本当に長かったので、私は私が使用しています地域のために出力を遮断。
出典
2017-01-26 00:03:43
Neo