简体   繁体   中英

How to reference Cloudformation Ressources in a new Cloudformation template?

I have two Cloudformation files and I want to reference already created Ressources from one template, in another template. For Example: In the first one I create an ECS Cluster. In the second one I want to reference this cluster and build a Service in it. How can I do it?

To do this you have to exporting stack output values from the first template. Presumably this would be ECS Cluster name and/or its arn:

MyCluster:
   Type: AWS::ECS::Cluster
   Properties: 
    #....

Outputs:
  MyClusterName:
     Value: !Ref MyCluster
     Export:
        Name: ECSClusterName

Then in the second template you would use ImportValue to reference the exported output:

MyESSService:
   Type: AWS::ECS::Service
   Properties: 
     Cluster: !ImportValue ECSClusterName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM