[英]How can I use Fn::GetAttr only when the resource exist?
I'm making one main stack and two nested stack.我正在制作一个主堆栈和两个嵌套堆栈。 The first nested stack is a stack which creates Lambda. And the second nested stack creates Apigateway.
第一个嵌套堆栈是创建 Lambda 的堆栈。第二个嵌套堆栈创建 Apigateway。
When making the Apigateway I send some Lambda outputs to the Apigateway template.在制作 Apigateway 时,我将一些 Lambda 输出发送到 Apigateway 模板。 But some Lambda Outputs don't get created in some conditions.
但是在某些情况下不会创建某些 Lambda 输出。
So when I use Fn::GetAttr
to send some outputs to the Apigateway template.因此,当我使用
Fn::GetAttr
将一些输出发送到 Apigateway 模板时。 I get an error because the output doesn't exist.我收到错误消息,因为 output 不存在。
[Lambda Template (Nested Stack)] [Lambda 模板(嵌套堆栈)]
Because of the condition conditionNeedMock
the MockServerArn output wasn't created.由于条件
conditionNeedMock
未创建 MockServerArn output。
...
Outputs:
MockServerArn:
Condition: conditionNeedMock
Description: lambdaMock function Arn
Value: !GetAttr lambdaMock.Arn
...
[Main Template] [主模板]
LambdaStack.Ouputs.MockserverArn
wasn't created so I get an error when using !GetAttr
.未创建
LambdaStack.Ouputs.MockserverArn
,因此在使用!GetAttr
时出现错误。
...
Resources:
LambdaStack:
Type: AWS::CloudFormation::Stack
...
ApiGatewayStack:
Type: AWS::CloudFormation::Stack
DependsOn: LambdaStack
Properties:
TemplateURL: apigateway.yml
TimeoutInMinutes: 20
Parameters:
paramMockServerArn: !GetAtt LambdaStack.Outputs.MockServerArn
...
The only way that could possibly work (without introducing custom resources) is if conditionNeedMock
is also in the root stack:唯一可行的方法(不引入自定义资源)是如果
conditionNeedMock
也在根堆栈中:
paramMockServerArn: !If [conditionNeedMock, !GetAtt LambdaStack.Outputs.MockServerArn, !Ref "AWS::NoValue"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.