问题
I am able to add 1 variable but unable to add second, I am a sys admin, and not that much knowledgeable about YAML
UserData:
Fn::Base64: !Sub
- |+
#!/bin/bash -xe
NEW_HOSTNAME=${test}
- test:
Fn::FindInMap: [Regions, !Ref "AWS::Region", Name]
I would like to add another FindInMap variable after test, but I am unable to.
回答1:
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.
回答2:
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] ] ]
}
来源:https://stackoverflow.com/questions/54564787/how-to-add-two-variables-in-cloudformation-fnsub-in-userdata