Creating AWS PrivateLink connections using AWS CloudFormation

0

I'm setting up infrastructure with CloudFormation including a VPC with subnets and an interface VPC endpoint.

The endpoint is meant to be deployed using the subnets created as part of the stack but when I start the deployment I get the following error:

The VPC endpoint service X does not support the availability zone of the subnet: subnet-Y

The endpoint service is deployed in subnets in the following AZs:

  • us-east-1a (use1-az1)
  • us-east-1b (use1-az2)
  • us-east-1c (use1-az4)

And the VPC in which I'm testing the CloudFormation stack have the subnets in the following AZs:

  • us-east-1a (use1-az2)
  • us-east-1b (use1-az4)
  • us-east-1c (use1-az6)

The only matching are use1-az2 and use1-az4.

I would like to know if there's a way to automatically lookup the supported AZs by the service and match them with my subnets' AZs.

The idea is to create 4 different environments with the same setup (VPC subnets, endpoint) so as to avoid hard coding the values.

AWS
已提問 3 年前檢視次數 788 次
1 個回答
0
已接受的答案

You can call DescribeVpcEndpointServices API via custom resource lambda in your CloudFormation, filtering for the specific service and then get the list of availability zones available to that service. You can then use this information in your other resources within the stack. Example output snippet via the AWS CLI:

{
    "ServiceDetails": [
        {
            "ServiceName": "aws.sagemaker.us-east-1.notebook",
            "ServiceId": "vpce-svc-0e123abc123198abc",
            "ServiceType": [
                {
                    "ServiceType": "Interface"
                }
            ],
            "AvailabilityZones": [
                "us-east-1a",
                "us-east-1b",
                "us-east-1c",
                "us-east-1d",
                "us-east-1e",
                "us-east-1f"
            ],
            "Owner": "amazon",
            "BaseEndpointDnsNames": [
                "vpce-svc-0e123abc123198abc.us-east-1.vpce.amazonaws.com",
                "notebook.us-east-1.vpce.sagemaker.aws"
            ],
            "PrivateDnsName": "*.notebook.us-east-1.sagemaker.aws",
            "VpcEndpointPolicySupported": true,
            "AcceptanceRequired": false,
            "ManagesVpcEndpoints": false,
            "Tags": [],
            "PrivateDnsNameVerificationState": "verified"
        },
...
}
AWS
已回答 3 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南