我正在尝试创建子网名称标签,但出现错误。我不知道是什么导致了错误。子网已成功创建,但是创建标签名称时出错。
pub_subnetid = pub_subnet['Subnet']['SubnetId']
TypeError: 'NoneType' object is not subscriptable
def addvpcnametag(self, tagid, resourcename):
print("creating tag name")
return self.client.create_tags(
Resources=[tagid],
Tags=[{'Key': 'Name', 'Value': resourcename}])
我主要有:
pub_subnet = vpc.addnew_subnet(tag_id, '10.0.2.0/24')
pub_subnetid = pub_subnet['Subnet']['SubnetId']
print("Adding public subnet name tag")
publicsubnetname_tag = 'Public-subnet'
vpc.addvpcnametag(pub_subnetid, publicsubnetname_tag)
答案 0 :(得分:0)
以下是在给定子网中设置Name
标签的一些代码:
import boto3
ec2_resource = boto3.resource('ec2')
subnet_id = 'subnet-abcd1234'
subnet = ec2_resource.Subnet(subnet_id)
subnet.create_tags(
Tags=[
{
'Key': 'Name',
'Value': 'Foo'
},
]
)