amazon-cloudformation - How can I check if a resource was created by CloudFormation?
问题描述
I have inherited an AWS account with a lot of resources. Some of them were created manually, other by CloudFormation.
How can I check if a resource (in my case Security Group) was created by CloudFormation and belongs to a stack?
For some security groups aws ec2 describe-security-groups --group-ids real_id
results in:
...
"Tags": [
{
"Value": "REAL_NAME",
"Key": "aws:cloudformation:logical-id"
},
{
"Value": "arn:aws:cloudformation:<REAL_ID>",
"Key": "aws:cloudformation:stack-id"
},
]
...
Other security groups don't have any tags.
Is it the only indicator? I mean, someone could easily remove tags form an SG created by CloudFormation.
解决方案
根据官方文档,除了您定义的任何标签外,AWS CloudFormation 还会自动创建以下堆栈级标签,前缀为 aws::
aws:cloudformation:逻辑 ID
aws:cloudformation:堆栈 ID
aws:cloudformation:堆栈名称
所有堆栈级标签(包括自动创建的标签)都会传播到 AWS CloudFormation 支持的资源。目前,标签不会传播到从块储存设备映射创建的 Amazon EBS 卷。
--
这应该是一个很好的起点,但由于 CF 不强制执行堆栈状态,因此如果有人手动删除了某些内容,那么您永远不会知道。
如果我是你,我会通过 Cloudformer 导出所有内容(支持)并按照我的方式重新设计整个设置。
另一种方式:
您可以将资源的PhysicalResourceId传递给describe_stack_resources,如果它属于 CF 堆栈,则可以获取堆栈信息。这是一个例子:
cf = boto3.client('cloudformation')
cf.describe_stack_resources(PhysicalResourceId="i-0xxxxxxxxxxxxxxxx")
推荐阅读
- cypress - 赛普拉斯 - 计算数组中包含特定字符串的元素数量
- java - REST API 如何从 POST URL 获取我的数据?
- python - 检查 Flask 会话 cookie 的大小
- zsh - 如果连续返回被击中,如何避免打印路径?
- python - 当播放音乐命令进入时,如何让 Discord 机器人跳过加入 VC 步骤
- node.js - 使用 nodejs 获取重定向数据
- r - 在收集:ed 数据的 facet_wrap 中向某些方面添加不同的行
- java - Spring Java 应用程序的拒绝服务 ReadLine 漏洞
- c# - 为什么方法重载会破坏 Azure 函数路由?
- javascript - 反应回调函数