スキップしてコンテンツを表示

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

モデレーター

質問済み 9年前3439ビュー

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

回答済み 9年前

エキスパート

レビュー済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

関連するコンテンツ