我正在开发一个AWS VPC,它有一个子网,默认情况下不会自动分配公共IP.我想使用boto3来创建实例并自动分配公共IP.目前尚不清楚如何从boto3文档中做到这一点.
我得到的最接近的是以下,但仍有错误:
self._ec2.create_instances(
ImageId=self._cluster._image,
KeyName="key_pair_1",
InstanceType="t2.micro",
MinCount=1,
MaxCount=1,
SecurityGroupIds=["sg-someid"],
SubnetId="subnet-anotherid",
BlockDeviceMappings=[{
"DeviceName": "/dev/sda1",
"Ebs": {
"VolumeType": "gp2",
"VolumeSize": disk_size,
"DeleteOnTermination": True
},
}],
NetworkInterfaces=[{
"DeviceIndex": 0,
"AssociatePublicIpAddress": True
}]
)
boto3 ×1