CloudFormation:Return 子网的 ARN

CloudFormation: Return ARN of Subnet

是否有另一种方法可以通过 Fn::GetAtt 内部函数获取 ARN 已创建的子网资源 AWS::EC2::Subnet。仅限子网资源 returns AvailabilityZone, Ipv6CidrBlocks, NetworkAclAssociationId, VpcId.

文档:https://docs.aws.amazon.com/en_pv/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html#aws-resource-ec2-subnet-return-values

因为子网的 ARN 格式为 arn:aws:ec2:REGION:ACCOUNT_ID:子网/SUBNET_ID。通过使用内部函数 Fn::Join 您可以生成子网的 ARN

示例:arn:aws:ec2:ap-southeast-1:767022272945:subnet/subnet-0d42d2235s3a2531d

  !Join
    - ''
    - - 'arn:aws:ec2:'
      - !Ref 'AWS::Region'
      - ':'
      - !Ref 'AWS::AccountId'
      - ':subnet/'
      - Fn::ImportValue:
          Fn::Sub: VPC-SubnetId