Reputation: 419
I am trying to create a subnet name tag but I'm getting the error. I have no idea what is causing the error. The subnet was successfully created, however, there is an error creating the tag name.
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}])
In the main i have:
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)
Upvotes: 2
Views: 975
Reputation: 269191
Here's some code that sets the Name
tag on a given subnet:
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'
},
]
)
Upvotes: 1