1

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?

Adiii
  • 54,482
  • 7
  • 145
  • 148

1 Answers1

1

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.

Mark B
  • 183,023
  • 24
  • 297
  • 295