AWS SDK - 如何使用 Boto3 设置 VPC 名称标签
AWS SDK - How to set the VPC name tag using Boto3
创建vpc时如何使用AWS SDK指定VPC名称标签?我尝试了此处显示的多种选项但没有成功。
下面是我如何使用 python、boto3 SDK 创建我的 VPC。
import os
import boto3
import time
....
....
print('Creating VPC')
# Create new VPC environment
vpc = client.create_vpc(CidrBlock='10.0.0.0/16', InstanceTenancy='default')
client.modify_vpc_attribute(VpcId=vpc['Vpc']['VpcId'], EnableDnsSupport={'Value': True})
client.modify_vpc_attribute(VpcId=vpc['Vpc']['VpcId'], EnableDnsHostnames={'Value': True})
目前,它创建的 vpc 没有名称标签。
我尝试在创建 vpc 期间或在如下所示修改它时指定标记,但 none 选项有效。
vpc = client.create_vpc(CidrBlock='10.0.0.0/16', InstanceTenancy='default', Tags="myvpcnametag")
client.modify_vpc_attribute(VpcId=vpc['Vpc']['VpcId'], Tags="myvpctag")
如果您有 VPC id:
client = boto3.client('ec2')
client.create_tags(Resources=['vpc-78a54011'], Tags=[{'Key': 'Name', 'Value': 'MyVPC'}])
这是我修改它的方法,效果很好。
创建新的 VPC 环境
vpc = client.create_vpc(CidrBlock='10.0.0.0/16', InstanceTenancy='default')
client.modify_vpc_attribute(VpcId=vpc['Vpc']['VpcId'], EnableDnsSupport={'Value': True})
client.modify_vpc_attribute(VpcId=vpc['Vpc']['VpcId'], EnableDnsHostnames={'Value': True})
client.create_tags(Resources=[vpc['Vpc']['VpcId']], Tags=[{'Key': 'Name', 'Value': 'DariusVPC'}])
创建vpc时如何使用AWS SDK指定VPC名称标签?我尝试了此处显示的多种选项但没有成功。
下面是我如何使用 python、boto3 SDK 创建我的 VPC。
import os
import boto3
import time
....
....
print('Creating VPC')
# Create new VPC environment
vpc = client.create_vpc(CidrBlock='10.0.0.0/16', InstanceTenancy='default')
client.modify_vpc_attribute(VpcId=vpc['Vpc']['VpcId'], EnableDnsSupport={'Value': True})
client.modify_vpc_attribute(VpcId=vpc['Vpc']['VpcId'], EnableDnsHostnames={'Value': True})
目前,它创建的 vpc 没有名称标签。
我尝试在创建 vpc 期间或在如下所示修改它时指定标记,但 none 选项有效。
vpc = client.create_vpc(CidrBlock='10.0.0.0/16', InstanceTenancy='default', Tags="myvpcnametag")
client.modify_vpc_attribute(VpcId=vpc['Vpc']['VpcId'], Tags="myvpctag")
如果您有 VPC id:
client = boto3.client('ec2')
client.create_tags(Resources=['vpc-78a54011'], Tags=[{'Key': 'Name', 'Value': 'MyVPC'}])
这是我修改它的方法,效果很好。
创建新的 VPC 环境
vpc = client.create_vpc(CidrBlock='10.0.0.0/16', InstanceTenancy='default')
client.modify_vpc_attribute(VpcId=vpc['Vpc']['VpcId'], EnableDnsSupport={'Value': True})
client.modify_vpc_attribute(VpcId=vpc['Vpc']['VpcId'], EnableDnsHostnames={'Value': True})
client.create_tags(Resources=[vpc['Vpc']['VpcId']], Tags=[{'Key': 'Name', 'Value': 'DariusVPC'}])