简体   繁体   中英

Can I define a parameter by using mappings in CloudFormation?

This is the important part of my template:

Parameters:

  EnvType:
    Description: Environment type.
    Type: String
    AllowedValues:
      - prod
      - test

Mappings:
  EnvDomain:
    Primary:
      prod: "prodexample.com"
      test: "testexample.com"

The question I have is can I add a parameter (under "Parameters:" of course) that has a value defined by Mappings? It would look something like this:

  DomainName:
    Type: String
    Default: !FindInMap ["EnvDomain", "Primary", "${EnvType}"

I'm not sure how to,Sub the EnvType in there? can !join be used or is this even possible?

From a semantic point of view i recommend the following:

  • Parameters are the variable input
  • Mappings are the static constants needed throughout the template

Use a combination of parameters and mappings inside the resource section, eg

!Sub
    - vpc-${myParam}-${myMapping}
    - myParam: !Ref Parameter1
      myMapping: !FindInMap [x, y, z]

The question I have is can I add a parameter (under "Parameters:" of course) that has a value defined by Mappings?

Sadly, you can't do this. Such functionality is not supported .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM