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}.

중재자
질문됨 6년 전2245회 조회
1개 답변
0
수락된 답변

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
답변함 6년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠