Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

amazon web services - How to pass CloudFormation parameter as Type: Number?

I am trying to create a Budget in an AWS account by deploying the following AWS CloudFormation Template (with Azure DevOps):

Parameters:
  EmailRecipients:
    Type: String
    Description: Name of the Email Recipient
  BudgetAmount:
    Type: Number
    Default: 500
    Description: Budget Amount
  AmountThreshold:
    Type: Number
    Default: 80
    Description: Budget Threshold

Resources:
  BudgetExample:
    Type: "AWS::Budgets::Budget"
    Properties:
      Budget:
        BudgetLimit:
          Amount: !Sub ${BudgetAmount}
          Unit: USD
        TimeUnit: MONTHLY
        BudgetType: COST
      NotificationsWithSubscribers:
        - Notification:
            NotificationType: ACTUAL
            ComparisonOperator: GREATER_THAN
            Threshold: !Sub ${AmountThreshold}
          Subscribers:
            - SubscriptionType: EMAIL
              Address: !Sub ${EmailRecipients}

But get the following error:

##[error]MultipleValidationErrors: There were 2 validation errors:
* InvalidParameterType: Expected params.Parameters[1].ParameterValue to be a string
* InvalidParameterType: Expected params.Parameters[2].ParameterValue to be a string

I have tried changing the Type from Number to String but with the same error. Also tried resolving the parameter by the other intrinsic function !Ref without luck. This is how I set the parameters for the CloudFormation template from a azure-pipelines.yml file:

variables:
  email_recipients: "[email protected]"
  budget_amount: 100
  amount_threshold: 80

And this is how they get passed them to template:

            - task: CloudFormationCreateOrUpdateStack@1
              displayName: budgets
              inputs:
                awsCredentials: ${{parameters.aws_credentials}}
                regionName: ${{parameters.aws_region}}
                stackName: ${{parameters.stack_name}}
                templateSource: 'file'
                templateFile: $(Pipeline.Workspace)/${{parameters.project_name}}-templates/budgets.yml
                templateParametersSource: "inline"
                templateParameters: |
                  - ParameterKey: EmailRecipients
                    ParameterValue: ${{parameters.email_recipients}}
                  - ParameterKey: BudgetAmount
                    ParameterValue: ${{parameters.budget_amount}}
                  - ParameterKey: AmountThreshold
                    ParameterValue: ${{parameters.amount_threshold}}
                useChangeSet: true
                changeSetName: 'role-changeset'
                captureStackOutputs: asVariables
                captureAsSecuredVars: false
question from:https://stackoverflow.com/questions/66050456/how-to-pass-cloudformation-parameter-as-type-number

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Parameters

Number:

An integer or float. AWS CloudFormation validates the parameter value as a number; however, when you use the parameter elsewhere in your template (for example, by using the Ref intrinsic function), the parameter value becomes a string.

---
AWSTemplateFormatVersion: 2010-09-09
Description: >-
    Deploy an instance of wallaby api to your AWS Organization.
Parameters:
  EmailRecipients:
    Type: String
    Description: Name of the Email Recipient
  BudgetAmount:
    Type: Number
    Default: 500
    Description: Budget Amount
  AmountThreshold:
    Type: Number
    Default: 80
    Description: Budget Threshold

Resources:
  BudgetExample:
    Type: "AWS::Budgets::Budget"
    Properties:
      Budget:
        BudgetLimit:
          Amount: !Ref BudgetAmount
          Unit: USD
        TimeUnit: MONTHLY
        BudgetType: COST
      NotificationsWithSubscribers:
        - Notification:
            NotificationType: ACTUAL
            ComparisonOperator: GREATER_THAN
            Threshold: !Ref AmountThreshold
          Subscribers:
            - SubscriptionType: EMAIL
              Address: !Ref EmailRecipients

cfn-lint check

$ cfn-lint cfn.yml
$ echo $?
0

UPDATE:

As the original post got updated. User created another post Pass Azure pipeline variable to AWS Cloudformation template as parameter with type: Number


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...