i working on aws vpc has 1 subnet not auto-assign public ip default. use boto3 create instance , automatically assign public ip. it's not clear how boto3 documentation.
the closest got following, still has errors:
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 }] )
if launch ec2 instance inside vpc subnet make private (without auto-assign public ip turn on), there 2 ways can make internet ready 1. attach elastic ip after create instances 2. create nat gateway reroute traffic subnet allow connect internet.
this instance network setup never overwrite vpc private subnet rules.
"associatepublicipaddress": true
if subnet features doesn't change auto-assign public ip, easiest way elastic ip. add 2 process 1. allocate_address : elastic ip address 2. associate_address : attach eip-id instance-id
Comments
Post a Comment