英文:
How to DescribeVPCs in a particular AWS region using Go AWS SDK?
问题
我想查询属于特定区域的所有VPC,该VPC是基于我的Go微服务的。
https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcs.html 表明不存在按区域或任何其他请求参数进行过滤的选项。
Golang SDK 参考文档:
https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#EC2.DescribeVpcs
命令行 SDK 参考文档:https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-vpcs.html
这是一个示例。
{
"Vpcs": [
{
"CidrBlock": "30.1.0.0/16",
"DhcpOptionsId": "dopt-19edf471",
"State": "available",
"VpcId": "vpc-0e9801d129EXAMPLE",
"OwnerId": "111122223333",
"InstanceTenancy": "default",
"CidrBlockAssociationSet": [
{
"AssociationId": "vpc-cidr-assoc-062c64cfafEXAMPLE",
"CidrBlock": "30.1.0.0/16",
"CidrBlockState": {
"State": "associated"
}
}
],
"IsDefault": false,
"Tags": [
{
"Key": "Name",
"Value": "Not Shared"
}
]
}
]
}
然而,如果我使用以下命令
$aws ec2 describe-vpcs --region us-west-1
那么我可以查询区域us-west-1
中的所有vpcs
。
问题1:为什么CLI SDK文档中没有提到--region
选项?
问题2:在使用GO SDK时,我该如何在DescribeVpcsInput
中加入相同的选项?
英文:
I want to query all VPCs belonging to a particular region in my Go-based microservice.
https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeVpcs.html indicates that there exists no filter option by region or any other request parameter.
Golang SDK reference document:
https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/#EC2.DescribeVpcs
Command line SDK reference document: https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-vpcs.html
Here's an example.
{
"Vpcs": [
{
"CidrBlock": "30.1.0.0/16",
"DhcpOptionsId": "dopt-19edf471",
"State": "available",
"VpcId": "vpc-0e9801d129EXAMPLE",
"OwnerId": "111122223333",
"InstanceTenancy": "default",
"CidrBlockAssociationSet": [
{
"AssociationId": "vpc-cidr-assoc-062c64cfafEXAMPLE",
"CidrBlock": "30.1.0.0/16",
"CidrBlockState": {
"State": "associated"
}
}
],
"IsDefault": false,
"Tags": [
{
"Key": "Name",
"Value": "Not Shared"
}
]
}
]
}
However, if I use the command
$aws ec2 describe-vpcs --region us-west-1
then I can query all vpcs
in region us-west-1
.
Question 1. Why is the --region
option not mentioned in the CLI SDK document?
Question 2. How can I incorporate the same in DescribeVpcsInput
while using GO SDK?
答案1
得分: 1
--region
标志在CLI上不是一个过滤器,而是一个必需的设置,用于告诉AWS CLI要连接到哪个区域。ec2 describe-vpcs
命令始终限制在单个区域内(大多数AWS命令都是如此)。
您还可以使用所需的区域配置AWS SDK客户端。请参阅此处的"指定AWS区域" 链接。
英文:
The --region
flag on the CLI is not a filter, it is a required setting that tells the AWS CLI what region to connect to. The ec2 describe-vpcs
command is always limited to a single region (most AWS commands are).
You would configure your AWS SDK client with the region you want it to connect to as well. See "Specifying the AWS Region" here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论