微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 CloudFormation 模板中正确使用 Fn::Join 对象?

如何解决如何在 CloudFormation 模板中正确使用 Fn::Join 对象?

我正在尝试使用 Fn::Join 函数创建安全组,但在构建模板时出现以下错误

✖ Template validation Failed.
An error occurred (ValidationError) when calling the ValidateTemplate operation: Template error: every Fn::Join object requires two parameters,(1) a string delimiter and (2) a list of strings to be joined or a function that returns a list of strings (such as Fn::GetAZs) to be joined.

在这里做错了什么?

  ContainerSecurityGroup:
    Type :  AWS::EC2::SecurityGroup
    Properties : 
       InstanceId: !Ref ContainerSG
       GroupDescription :  "ECS Containers Security Group"
       VpcId : 
         "Fn::Join" :
                -  ""
                - -  "{{resolve:ssm:"
                -  /
                -  "ca"
                -  /
                -  "config"
                -  /
                -  "network"
                -  /
                -  "vpc_id:"
                -  !Sub   "${ParamVersion}"
                -  "}}"
       GroupName :  !Sub   ${Env}-${ServiceName}-sg
       SecurityGroupIngress :
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  10.49.63.0/24
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  10.93.0.0/16
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  10.97.0.0/16
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  10.50.128.0/21
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  10.50.144.0/24
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  172.25.0.0/16

这是某人发给我的样本,但我不知道出了什么问题。

解决方法

需要缩进的字符串列表:

ContainerSecurityGroup:
    Type :  AWS::EC2::SecurityGroup
    Properties : 
       InstanceId: !Ref ContainerSG
       GroupDescription :  "ECS Containers Security Group"
       VpcId : 
         !Join :
                -  ""
                - -  "{{resolve:ssm:"
                  -  /
                  -  "ca"
                  -  /
                  -  "config"
                  -  /
                  -  "network"
                  -  /
                  -  "vpc_id:"
                  -  !Sub   "${ParamVersion}"
                  -  "}}"
       GroupName :  !Sub   ${Env}-${ServiceName}-sg
       SecurityGroupIngress :
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  10.49.63.0/24
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  10.93.0.0/16
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  10.97.0.0/16
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  10.50.128.0/21
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  10.50.144.0/24
        -  IpProtocol :  tcp
           FromPort :  8080
           ToPort :  8080
           CidrIp :  172.25.0.0/16

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。