CloudFormation User Parameter as another parameter Default Value

0

Hello,

I keep getting this error

Template Format error parameter default has to be string and i want to use a Parameter as another Parameter Default.

Parameters:
  AppId:
    Type: String
    Default: "mygradecard-iac"
  RepositoryName:
    Type: String
    Default: !Sub "${AppId}-Respository"
    Description: "Name of the Repository to be Created"

Thank you

Nafiu
質問済み 9ヶ月前432ビュー
1回答
2
承認された回答

Hi,

You cannot do that so directly: as said by the message, a parameter is a string, you cannot call something like !Sub in a parameter defintion

But, there are solutions: I personally use SSM parameters to achieve what you want. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-parameter.html

BasicParameter:
    Type: AWS::SSM::Parameter
    Properties:
      Name: MyParam
      Type: String
      Value: 'xyz'
      Description: SSM Parameter for running date command.

In Value, you can use !Sub or any function.

Then, you obtain your value by calling !GetAtt MyParam.Value. Additional advantage, the SSM console will allow you to easily see the result of your value computation.

It works great for me. I wish that it will be same for you.

Best,

Didier

profile pictureAWS
エキスパート
回答済み 9ヶ月前
  • Thank you, Very Explanatory Resource

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

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

質問に答えるためのガイドライン

関連するコンテンツ