简体   繁体   中英

EC2 - Create Instance params for javascript aws sdk

var params = {
     ImageId: 'ami-23ebb513',
     InstanceType: 't1.micro',
     MinCount:1, MaxCount: 1

};

ec2.runInstances(params, function(err, data) {
})

This code is good to start with launch instances. But i am trying to customize the instance's security group, public key for ssh etc. How can we configure these params? I see not much docs is available that lists out the params supported by aws-sdk .

You should be able to get most of what you want with params.

Params additions would be:

NetworkInterfaces: [{DeviceIndex:0, SubnetId: 'subnet-12345', AssociatePublicIpAddress:true, Groups: ['sg-12345']}],

KeyName: 'MyKey'

The only thing you can't really get with the ec2-runInstances is tag creation. That would come from a second api call within the first function, like so:

params = {Resources: [data['instanceId']], Tags: [
  {Key: 'Name', Value: 'SomeName-' + data['instanceId']},
  {Key: 'Project', Value: 'My Project'},
  {Key: 'SubProject', Value: 'SpotInstanceAuto'},
  {Key: 'Creator', Value: 'Jason Nichols'},
  ...
]};
ec2.createTags(params, function(err) {
  console.log("Tagging instance", err ? "failure" : "success");
  ...
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM