使用 AWS SDK 启动 ec2 实例时指定存储
Specify storage when launching ec2 instance with AWS SDK
在 docs how to specify the root storage when starting a new ec2 instance. If I start an instance through the web interface, I can go through this step:
中找不到
在启动实例之前更改存储设置。我如何使用 SDK 做到这一点?目前我有:
AWS = require('aws-sdk');
var ec2 = new AWS.EC2({
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
region: 'us-east-1'
});
var params = {
ImageId: 'ami-123456',
InstanceType: 't2.micro',
MinCount: 1, MaxCount: 1,
SecurityGroups: [
'my-security-group',
],
// how to specify storage settings??
};
// Create the instance
ec2.runInstances(params, function(err, data) {
if (err) { console.log("Could not create instance", err); return; }
var instanceId = data.Instances[0].InstanceId;
console.log("Created instance", instanceId);
});
BlockDeviceMappings:[{
DeviceName:'/dev/sda1',
Ebs:{
VolumeSize:8,
DeleteOnTermination:true,
VolumeType:"gp2",
}
}]
在 docs how to specify the root storage when starting a new ec2 instance. If I start an instance through the web interface, I can go through this step:
在启动实例之前更改存储设置。我如何使用 SDK 做到这一点?目前我有:
AWS = require('aws-sdk');
var ec2 = new AWS.EC2({
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
region: 'us-east-1'
});
var params = {
ImageId: 'ami-123456',
InstanceType: 't2.micro',
MinCount: 1, MaxCount: 1,
SecurityGroups: [
'my-security-group',
],
// how to specify storage settings??
};
// Create the instance
ec2.runInstances(params, function(err, data) {
if (err) { console.log("Could not create instance", err); return; }
var instanceId = data.Instances[0].InstanceId;
console.log("Created instance", instanceId);
});
BlockDeviceMappings:[{
DeviceName:'/dev/sda1',
Ebs:{
VolumeSize:8,
DeleteOnTermination:true,
VolumeType:"gp2",
}
}]