gpt4 book ai didi

amazon-web-services - 如何将 CloudFormation 参数作为类型 : Number? 传递

转载 作者:行者123 更新时间:2023-12-03 07:12:39 26 4
gpt4 key购买 nike

我尝试通过部署以下 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

我尝试将TypeNumber更改为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

最佳答案

Parameters

数字:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com