Cloudformation-无法导入资源 [英] Cloudformation - Unable to Import resource
问题描述
我正在创建Step Functions,并想在cloudformation代码中引用Lambda函数。该lambda已从单独的堆栈中创建,并从该堆栈中导出为 LambdaA
。
I am creating Step Functions and would like to reference a Lambda function in the cloudformation code. The lambda is already created from separate stack and is exported as LambdaA
from that stack.
我遇到了问题当我尝试将 LambdaA
导入到我的步进函数代码中时。
I am running into issue when I try to import LambdaA
into my step function code.
这是我的cloudformation片段。
Here is my cloudformation snippet.
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控制台中收到以下错误:
I get the following error in Cloudformation console:
无效的状态机定义: / DoStuff / Resource上的SCHEMA_VALIDATION_FAILED(服务:AWSStepFunctions;状态码:400;错误代码:InvalidDefinition。
Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED at /DoStuff/Resource' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition.
关于这里可能出什么问题的任何想法?
Any idea as to what might be wrong here?
推荐答案
您不能在 Fn :: Sub
函数内使用其他内部函数。但是 Fn :: Sub
提供了解决此问题的方法。它的工作方式有点像 format
函数将在其他编程语言中工作。这是针对您的特定情况的一个示例:
You can't use other intrinsic function inside Fn::Sub
function. But Fn::Sub
offers a way to solve this. It works a bit like a format
function would work in other programming languages. Here's an exemple for your particular case:
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
这篇关于Cloudformation-无法导入资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!