How to add two variables in Cloudformation Fn::Sub in UserData

僤鯓⒐⒋嵵緔 提交于 2019-12-04 22:02:48

You can do it like this:

UserData:
  Fn::Base64: !Sub
    - |
      #!/bin/bash -xe
      foo=${foo}
      baz=${baz}
    - foo: !FindInMap [FooMap, Foo, Value]
      baz: !FindInMap [FooMap, Baz, Value]

It could also be formatted as:

UserData:
  Fn::Base64: !Sub
    - |
      #!/bin/bash -xe
      foo=${foo}
      baz=${baz}
    - {
        foo: !FindInMap [FooMap, Foo, Value],
        baz: !FindInMap [FooMap, Baz, Value]
      }

See also docs for the Fn::FindInMap function.

Note that I removed the |+ - which is a YAML feature and says to keep the trailing newlines. It isn't really required here.

UserData: 
              Fn::Base64: !Sub
               - |
                  #!/bin/bash
                  NEW_HOSTNAME=${hostName}
               -  {
                  share: !FindInMap [Regions, !Ref "AWS::Region", SHARE],
                  hostName: !Join ["", [!Ref Name, !FindInMap [Regions, 
                                                         !Ref"AWS::Region",USERDATA] ] ]
                  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!