我正在创建StepFunction,它们引用在单独的cloudformation堆栈中创建的Lambda函数。 我将Lambda arn导出到CloudFormation导出。 而且我想通过导入导出的值来实现从StepFunctions引用Lambda函数。
这是我的cloudformation片段。
StepFunction:
Type: 'AWS::StepFunctions::StateMachine'
Properties:
RoleArn: !GetAtt IamRole.Arn
DefinitionString:
Fn::Sub:
- |-
{
"StartAt": "MessageGenerator",
"States": {
"MessageGenerator": {
"Comment": "generate queue message.",
"Type": "Task",
"Resource": "${LambdaMessageGenerator}",
"ResultPath": "$",
"OutputPath": "$",
"Next": "WaitSeconds"
},
...
}
}
- LambdaMessageGenerator:
Fn::ImportValue: some-export-name
我按照下面的答案做了。 Cloudformation - Unable to Import resource
但是,aws cloudformation deploy
命令失败,并且出现以下错误。
Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: Value is not a valid resource ARN at /States/MessageGenerator/Resource' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition; Request ID: 01713d53-4605-11e9-9cf3-c15ff9ce09ae)
有人可以帮我吗?
答案 0 :(得分:1)
为什么不只使用ImportValue
函数的缩写形式?
DefinitionString:
Fn::Sub:
- |-
{
"StartAt": "MessageGenerator",
"States": {
"MessageGenerator": {
"Comment": "generate queue message.",
"Type": "Task",
"Resource": "${LambdaMessageGenerator}",
"ResultPath": "$",
"OutputPath": "$",
"Next": "WaitSeconds"
},
...
}
}
- LambdaMessageGenerator: !ImportValue some-export-name
答案 1 :(得分:0)
尝试使用此行:
"Resource": "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunctionName}"
在这种情况下,您只需要传递lambda函数的名称。