考虑以下代码:
EventRule:
Type: AWS::Events::Rule
Properties:
Description: "ny trigger"
ScheduleExpression: "rate(1 minute)"
State: "DISABLED"
Targets:
-
Arn: !GetAtt MyFunctionLambdaFunction.Arn
Id: "someId"
Input:
Fn::Sub:
- '{"arn":"#{arn}"}'
- arn: !GetAtt MyStateMachine.Arn
这给了我一个错误:
Error: The CloudFormation template is invalid: Template error: One or more Fn::Sub
intrinsic functions don't specify expected arguments. Specify a string as first argument,
and an optional second argument to specify a mapping of values to replace in the string
最佳答案
此处的 Sub
中不需要 GetAtt
。 Sub
可以解析诸如 MyStateMachine.Arn
之类的内容。所以你可以这样做:
Input: !Sub
- |-
{ "arn": "${MyStateMachine.Arn}" }
在某些情况下,您可能仍然需要传入参数(例如,当您需要调用 ImportValue
等函数时)。例如,如果您的状态机在不同的堆栈中定义并通过 other-stack-MyStateMachine-Arn
输出导出,您可以执行以下操作:
Input: !Sub
- |-
{ "arn": "${MyStateMachineArn}" }
- MyStateMachineArn: !ImportValue
'Fn::Sub': 'other-stack-MyStateMachine-Arn'
关于amazon-web-services - 如何在无服务器中使用 Sub 函数和 GetAtt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57906573/