Python boto3中弹性IP与NAT网关的关联
我想请求一些关于在boto3中关联弹性IP和NAT网关的帮助 分配一个新的弹性IP地址 eip=client.allocate_地址(Domain='vpc') 创建NAT网关并分配给弹性IP nat_gw=client.create_nat_网关(SubnetId=subnet1.id,AllocationId=eip.id) eip=ec2\u客户端。分配\u地址(Domain='vpc') ec2_client.create_nat_gateway(SubnetId=subnet1.id,AllocationId=eip.id) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 AttributeError:“dict”对象没有属性“id”Python boto3中弹性IP与NAT网关的关联,python,amazon-web-services,boto3,Python,Amazon Web Services,Boto3,我想请求一些关于在boto3中关联弹性IP和NAT网关的帮助 分配一个新的弹性IP地址 eip=client.allocate_地址(Domain='vpc') 创建NAT网关并分配给弹性IP nat_gw=client.create_nat_网关(SubnetId=subnet1.id,AllocationId=eip.id) eip=ec2\u客户端。分配\u地址(Domain='vpc') ec2_client.create_nat_gateway(SubnetId=subnet1.id,
谢谢。既然是口述,你不这样做吗
nat_gw = client.create_nat_gateway(SubnetId=subnet1['id'],AllocationId=eip['id'])
**我假设subnet1
和eip
都是dict
我无法验证您是否正确执行了此操作,但上面的内容应该可以解决您看到的错误。我已设法以这种方式解决了此问题。(但这不是我喜欢的方式)
谢谢你的帮助。
import boto3
ec2 = boto3.resource('ec2', region_name="eu-west-2")
client = boto3.client('ec2', region_name="eu-west-2")
vpc = ec2.create_vpc(CidrBlock='10.10.0.0/16')
subnet1 = vpc.create_subnet(CidrBlock='10.10.1.0/24',AvailabilityZone='eu-west-2a')
subnet1.meta.client.modify_subnet_attribute(SubnetId=subnet1.id, MapPublicIpOnLaunch={"Value": True})
eip_for_nat_gateway = ec2_client.allocate_address(Domain='vpc')
>>> a = client.describe_addresses()
>>> for b in a['Addresses']:
...print b['AllocationId']
eipalloc-3790c652
>>> c= b['AllocationId']
>>> print c
eipalloc-3790c652
#Now I assign c as AllocationId
nat_gw = client.create_nat_gateway(SubnetId=subnet1.id,AllocationId=c)