带有 --tag-specifications 的 VPC 标签

Tags for VPC with --tag-specifications

EC2 有创建标签的选项;我们可以使用 cli 向 VPC 或任何其他具有 --tag-specifications 的 ARN 添加标签吗?我尝试了以下

aws ec2 create-vpc --cidr-block 193.164.0.0/16 --instance-tenancy default --tag-specifications 'ResourceType=instance,Tags=[{Key=webserver,Value=production}]' 'ResourceType=volume,Tags=[{Key=cost-center,Value=cc123}]'

错误: Unknown options: --tag-specifications, ResourceType=volume,Tags=[{Key=cost-center,Value=cc123}], ResourceType=instance,Tags=[{Key=webserver,Value=production}]

--tag-specifications 是 AWS CLI 中相对较新的功能。

截至目前 (AWS CLI 1.11.178),只有 EC2 instancesvolumes 可以在创建资源时进行标记。尚不支持在创建时标记 VPC。

要检查 aws.exe 命令是否支持选项,请使用 --generate-cli-skeleton 命令行选项。示例:

aws ec2 create-vpc --generate-cli-skeleton

此命令的输出是:

{
    "CidrBlock": "",
    "AmazonProvidedIpv6CidrBlock": true,
    "DryRun": true,
    "InstanceTenancy": "host"
}

从命令输出中您可以验证没有标签选项。

在您的问题中,您询问了有关标记 VPC 的问题。以下是此案例的示例命令:

aws ec2 create-tags --resources vpc-30783443 --tags Key=Network,Value=Default

现在可以选择在使用 AWS Tools for Powershell Cmdlet 时标记 VPC。

这可以通过首先指定您希望使用的标签、创建 VPC 并随后应用标签来实现。 例如:

# Name Tag for the VPC
$TagVPCName = New-Object Amazon.EC2.Model.Tag
$TagVPCName.Key = "Name"
$TagVPCName.Value = "Tenancy/Customer 0"

# Name Tag for Other Services
$TagVPCPurpose = New-Object Amazon.EC2.Model.Tag
$TagVPCPurpose.Key = "Purpose"
$TagVPCPurpose.Value = "Dev Environment"

$network = '172.16.0.0/16'
New-EC2Vpc -CidrBlock $network -InstanceTenancy default -Region
New-EC2Tag -Resource $EC2VPC.VpcId -Tag $TagVPCName
New-EC2Tag -Resource $EC2VPC.VpcId -Tag $TagVPCPurpose

可在以下位置找到更多信息:

https://spr.com/powershell-function-provision-windows-server-ec2-instance-aws-cloud/

https://github.com/jbernec/AmazonWebServices/blob/master/New-AWSNonDefaultEC2Instance.ps1

https://docs.amazonaws.cn/powershell/latest/reference/

运行 一行中的命令。不要 运行 多行。

例如:

aws ec2 create-vpc --cidr-block 10.0.0.0/16 --tag-specifications 'ResourceType=vpc, Tags=[{Key=Name,Value=EMR-VPC}]'