gpt4 book ai didi

amazon-web-services - CloudFormation 伪参数

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

我正在创建一个 AWS CodeStar 项目,并创建了 template.yml,其中包含 Lambda 函数、SF、DynamoDB 表。

如果我输入硬编码的区域和帐户 ID,它就可以工作,但是当我用 ${AWS::Region} 等参数替换它们时或${AWS::AccountId}我收到此错误:

Failed to execute change set. Current stack status: UPDATE_ROLLBACK_COMPLETE. Reason: No reason was provided.

这是我的 template.yml 的一部分

Resources:

DataAgentIntercept:
Type: AWS::StepFunctions::StateMachine
Properties:
StateMachineName: DataAgentIntercept
DefinitionString: |-
{
"StartAt": "InsertAgentDataDB",
"States": {
"InsertAgentDataDB": {
"Type": "Task",
"Resource": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:awscodestar-pocawsjawa-lambda-InsertAgentDataDB-10UOAYKYNWLYB",
"End": true
}
}
}
RoleArn: arn:aws:iam::${AWS::AccountId}:role/service-role/StatesExecutionRole-eu-west-1

我做错了什么?

最佳答案

默认情况下,字符串只是文字值。如果要执行任何替换,则需要使用 Fn::Sub (在 YAML 中,您可以使用简写符号 !Sub):

  StateMachineName: DataAgentIntercept
DefinitionString: !Sub |-
{
"StartAt": "InsertAgentDataDB",
"States": {
"InsertAgentDataDB": {
"Type": "Task",
"Resource": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:awscodestar-pocawsjawa-lambda-InsertAgentDataDB-10UOAYKYNWLYB",
"End": true
}
}
}
RoleArn: !Sub "arn:aws:iam::${AWS::AccountId}:role/service-role/StatesExecutionRole-eu-west-1"

关于amazon-web-services - CloudFormation 伪参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50812685/

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