Reputation: 97
When creating the elastic IP in AWS via boto3. API does not give an option to add Name to the elastic IP but this field is available via UI. How can I add Name to elastic IP while creating it or after?
Following code work:
import boto3
client = boto3.client('ec2')
addr = client.allocate_address(Domain='vpc')
print addr['PublicIp']
But, if I add "name" field, it throws this error:
ParamValidationError: Parameter validation failed: Unknown parameter in input: "Name", must be one of: DryRun, Domain
Upvotes: 0
Views: 264
Reputation: 78573
Generally in AWS, there are no Name
properties. What you're looking at there in the AWS console is actually a tag whose key is Name
. Almost all AWS objects can have Name
tags.
With boto3, you can use the create_tags() method to set one or more tags. For example:
import boto3
client = boto3.client('ec2')
response = client.create_tags(
Resources=[
'eipalloc-12344567890'
],
Tags=[
{
'Key': 'Name',
'Value': 'prod-eip'
}
]
)
Upvotes: 2
Reputation: 3044
What you see there is a tag. It doesn't appear that Elastic IPs support "Tag-On-Create", so you have to create the tag after the EIP has been created.
Try the following:
import boto3
client = boto3.client('ec2')
addr = client.allocate_address(Domain='vpc')
print(addr['PublicIp'])
response = client.create_tags(
Resources=[
addr['AllocationId'],
],
Tags=[
{
'Key': 'Name',
'Value': 'production',
},
],
)
print(response)
Upvotes: 2