CloudFormation 伪参数
CloudFormation Pseudo Parameters
我正在制作一个 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 中你可以使用 shorthand notaiton !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"
我正在制作一个 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 中你可以使用 shorthand notaiton !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"