Using pseudo parameters as defaults in cloudformation

1

I'm trying to create a CloudFormation script in which I set two default parameters using AWS Pseudo-Parameters. The cloudformation validate-template cli tells me "An error occurred (ValidationError) when calling the ValidateTemplate operation: Template format error: Every Default member must be a string.

I've tried returning a string using the !Ref, !Sub, !Base64, and combinations therein. I do know you can't do two shorthands (i.e. !Base64 !Sub AWS::Region) but have to do one long and one short {i.e. Fn::Base64: !Sub AWS Region), I tried calling it as a variable in text '${AWS::Region}' and without the single quotes. Is there any way to make this work?

Here's my code as it stands now:

Parameters:
    BuildRegion:
        Type: String
        AllowedValues:
          - us-east-1
          - us-east-2
          - us-west-1
          - us-west-2
          - ca-central-1
          - ap-south-1
          - ap-northeast-2
          - ap-southeast-1
          - ap-southeast-2
          - ap-northeast-1
          - eu-central-1
          - eu-west-1
          - eu-west-2
          - sa-east-1
        Default: !Sub AWS::Region
    NewBucketName:
        Type: String
        Default: !Join
                    - ''
                    - - Fn::Base64:
                        - !Sub AWS::AccountId
                    - '-bucket'
  • The following did work for me for the region:

      Region:
        Description: AWS Region
        Type: String
        Default: ${AWS::Region}

    However, the same did not work for ${AWS::AccountId}.

MODERATOR
asked 7 years ago2433 views
1 Answer
0
Accepted Answer

I don't think this is a supported or valid configuration.

You're using a resource Type of "string" but the default you're providing is not a "string".

Region isn't a valid AWS special parameter type to be used in Resource: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#aws-specific-parameter-types

To move forward you will probably need to pick a default value from your AllowedValues (like "us-east-1"). Slightly less convenient than having the current region populated.

As an aside - CloudFormation doesn't operate cross region. So if you're intending to use this region parameter later during resource creation it probably won't work!

AWS
answered 7 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions