我正在尝试通过部署以下 AWS CloudFormation 模板(使用 Azure DevOps)在 AWS 账户中创建预算:
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}
但得到以下错误:
##[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
我尝试将 Type
从 Number
更改为 String
,但出现相同的错误。
还尝试通过其他内在函数 !Ref
解析参数,但没有运气。
这是我从 azure-pipelines.yml 文件为 CloudFormation 模板设置参数的方式:
variables:
email_recipients: "example@gmail.com"
budget_amount: 100
amount_threshold: 80
这就是他们如何将它们传递给模板:
- 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
答案 0 :(得分:2)
Number
:
整数或浮点数。 AWS CloudFormation 将参数值验证为数字;但是,当您在模板中的其他地方使用该参数时(例如,通过使用 Ref 内部函数),该参数值将变成字符串。
---
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 检查
$ cfn-lint cfn.yml
$ echo $?
0
更新:
随着原始帖子的更新。用户创建了另一个帖子 Pass Azure pipeline variable to AWS Cloudformation template as parameter with type: Number