Aws lambda Cloudformation-无法导入资源
我正在创建Step函数,并希望在cloudformation代码中引用Lambda函数。lambda已经从单独的堆栈创建,并从该堆栈导出为lambda 当我试图将LambdaA导入我的step函数代码时,我遇到了问题 这是我的云信息片段Aws lambda Cloudformation-无法导入资源,aws-lambda,amazon-cloudformation,aws-step-functions,Aws Lambda,Amazon Cloudformation,Aws Step Functions,我正在创建Step函数,并希望在cloudformation代码中引用Lambda函数。lambda已经从单独的堆栈创建,并从该堆栈导出为lambda 当我试图将LambdaA导入我的step函数代码时,我遇到了问题 这是我的云信息片段 ABCStateMachine: Type: 'AWS::StepFunctions::StateMachine' Properties: StateMachineName: 'AbcStateMachine_1.0' RoleArn: Fn:
ABCStateMachine:
Type: 'AWS::StepFunctions::StateMachine'
Properties:
StateMachineName: 'AbcStateMachine_1.0'
RoleArn:
Fn::GetAtt: [ AbcStateMachineRole, Arn ]
DefinitionString:
Fn::Sub:
- |-
{
"StartAt": "DoStuff",
"Version": "1.0",
"States": {
"DoStuff" : {
"Type": "Task",
"Comment": "Does some stuff.,
"Resource": {"Fn::ImportValue": "LambdaA"}, # error here
"Next": "IsStuffDone"
},
"IsStuffDone": {
"Type": "Choice",
...
...
我在Cloudformation控制台中遇到以下错误:
无效的状态机定义:'SCHEMA\u VALIDATION\u在/DoStuff/Resource'服务失败:AWSStepFunctions;身份代码:400;错误代码:InvalidDefinition
您知道这里可能有什么问题吗?您不能在Fn::Sub函数中使用其他内在函数。但是Fn::Sub提供了一种解决这个问题的方法。它的工作原理有点像其他编程语言中的格式函数。以下是您的具体案例的一个示例:
ABCStateMachine:
Type: 'AWS::StepFunctions::StateMachine'
Properties:
StateMachineName: 'AbcStateMachine_1.0'
RoleArn:
Fn::GetAtt: [ AbcStateMachineRole, Arn ]
DefinitionString:
Fn::Sub:
- |-
{
"StartAt": "DoStuff",
"Version": "1.0",
"States": {
"DoStuff" : {
"Type": "Task",
"Comment": "Does some stuff.,
"Resource": ${LambdaToImport}, # error here
"Next": "IsStuffDone"
}
...
}
...
}
- LambdaToImport:
Fn::ImportValue: LambdaA