作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试通过部署以下 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: "exam<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="63130f0623040e020a0f4d000c0e" rel="noreferrer noopener nofollow">[email protected]</a>"
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
最佳答案
数字
:
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检查
$ cfn-lint cfn.yml
$ echo $?
0
更新:
随着原始帖子的更新。用户创建了另一个帖子 Pass Azure pipeline variable to AWS Cloudformation template as parameter with type: Number
关于amazon-web-services - 如何将 CloudFormation 参数作为类型 : Number? 传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66050456/
我是一名优秀的程序员,十分优秀!