2016-10-11 88 views
0

無法在docs中找到如何在啓動新的ec2實例時指定根存儲。如果我通過Web界面啓動實例,則可以執行此步驟:enter image description here使用AWS軟件開發工具包啓動ec2實例時指定存儲

在啓動實例之前更改存儲設置。我怎麼用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); 
}); 

回答

1

BlockDeviceMappings:[{ DeviceName:'/dev/sda1', Ebs:{ VolumeSize:8, DeleteOnTermination:true, VolumeType:"gp2", } }]

+1

優秀的,謝謝。最後你有一個錯字:'']' – Guig