我正在创建一个AppSync cloudformation和一个仪表板,并且我注意到ApiId导出已在很长时间之后完成创建。
我像这样在appsync文件中创建输出:
Outputs:
GraphQlApiIdOutput:
Description: Main GraphQl Api ID.
Value:
Fn::GetAtt:
- GraphQlApi
- ApiId
Export:
Name: GraphQlApiIdOutput
在另一个仪表板文件中:
CloudwatchDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardBody:
{
'Fn::Sub': ['{
...
,{
ApiId:
!ImportValue GraphQlApiIdOutput}]
但是,我得到了错误:No export named GraphQlApiIdOutput found. Rollback requested by user.
解决此问题的唯一方法是先删除导入值,以使堆栈创建成功,然后添加导入值。我注意到有一个等待条件,但是没有任何资源是外部的。我还注意到,仅AWS::AutoScaling::AutoScalingGroup, AWS::EC2::Instance, and AWS::CloudFormation::WaitCondition
支持创建策略。是否有一种方法等待Cloudformation中的资源创建,以便模板在同一堆栈中创建之前不会尝试使用输出值?
是,请使用DependsOn Attribute:
使用
DependsOn
属性,您可以指定在创建另一个特定资源之后。当您向资源添加DependsOn
属性时,仅在创建DependsOn
属性中指定的资源之后才创建该资源。
该属性指向同一堆栈中的另一个资源。如果资源A DependsOn
资源B,则仅在资源B完成创建后才创建资源A。
当您在代码中包含此内容时:
!ImportValue GraphQlApiIdOutput
这意味着来自Template 1
的堆栈必须预先创建。
因此通常您会执行以下操作:
Template 1
another template file
。DependsOn
用于相同堆栈中的资源,不用于不同堆栈。 WaitCondition
同样适用,因为您无法在成功创建another template file
堆栈之前从Template 1
引用Template 1
中的条件。