如何使用!ImportValue通过AWS SAM模板获取资源



我有一个基本模板,输出部分是这样的:

Outputs:
layerName:
Value: !Ref Psycopg2LayerLambdaLayer

如何在我的新模板中使用基础模板的输出获得Psycopg2LayerLambdaLayer的臂?这是正确的吗?

Layers: !ImportValue layerName.arn

如果您想在不同的模板中使用Output值作为Import,您必须首先导出它。在您的示例中,它可能如下所示:

Outputs:
layerArn:
Value: !GetAtt Psycopg2LayerLambdaLayer.arn
Export:
Name: psycopg2LayerArn

部署后,您可以使用!ImportValue psycopg2LayerArn将该值导入到另一个堆栈中。

请注意,每个帐户和区域的导出必须具有唯一的名称,因此使用堆栈/资源名称作为前缀是一个好主意。还要注意,不能导出对象,只能导出标量值,如字符串。

在https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html阅读更多

最新更新