如何引用其中创建的cloudformation中的资源

How to refer resources in cloudformation created in it

我想创建一个监控实例,有权在创建它的 cloudformation 范围内终止、创建、销毁实例、自动缩放组、标签等。

我应该为政策提供什么资源才能使其发挥作用?

 {                                                                                         
            "PolicyName": "ManageCloudformationInstances",                                                         
            "PolicyDocument": {                                                                     
              "Statement": [                                                                        
                {                                                                                   
                  "Effect": "Allow",                                                                
                  "Action": [                                                                       
                    "ec2:*"                                          
                  ],                                                                                
                  "Resource": "?????"                                                                   
                }                                                                                   
              ]                                                                                     
            }                                                                                       
          },                 

所以我猜你的问题有两个部分。

如果您在 cloudformation 模板中创建实例,那么您可以轻松地使用 GetAtt function 为这些资源提取 Arn

但是,如果您尝试动态允许它删除自动缩放组内的实例,那么您需要动态编辑您的策略以允许这样做。想到的最简单的方法是每次您的 ASG 扩展时触发 lambda 函数,并编辑策略以包含来自最近扩展的 ARN activity.

对于 ASG,您可能想从这样的事情开始 - http://docs.aws.amazon.com/autoscaling/latest/userguide/cloud-watch-events.html