amazon-web-services - 有没有办法向自动化 AWS Redshift 快照添加标签?
问题描述
我的问题非常简单——您能否将标签列表附加到 AWS 将为集群拍摄的自动集群快照中?
一些背景知识,当我们手动创建快照时,我们上传了一系列标签以及 CreateClusterSnapshot 请求,允许我们将快照与用户关联(因此使他们能够在以后从“终止”实例恢复红移集群。不幸的是,自动快照(通过 withAutomatedSnapshotRetentionPeriod 设置启用)到达 aws 时未加标签,因此除了手动添加标签外,我们无法将它们与最终用户相关联。
谢谢!
解决方案
目前在 Terraform 中无法做到这一点。我向 AWS 提出请求,要求他们将此功能添加到 redshift。如果您想将集群标签添加到自动快照,您可能会认为只需选中一个框即可。
自动快照不会生成 cloudtrail 日志,因此您不能执行此事件驱动(据我所知),它必须执行一个经常运行以查找快照的 cron 作业。
import json import boto3 def lambda_handler(event, context): client = boto3.client('redshift') response = client.describe_cluster_snapshots() for i in range(len(response["Snapshots"])): #Count number of Tags assoicated with Snapshot NumofTags = len(response["Snapshots"][i]["Tags"]) #Get the name of the cluster the snapshot is for clustername = response["Snapshots"][i]["ClusterIdentifier"] #Create the ARN for the snapshot arn = "arn:aws:redshift:us-east-1:631284890255:snapshot:" + clustername + "/" + str(response["Snapshots"][i]["SnapshotIdentifier"]) #if snapshot has no tags get tags from cluster and append tags to snapshot if NumofTags == 0: try: #Get Cluster information cl_response = client.describe_clusters(ClusterIdentifier=clustername) #Get tags from cluster clustertags = cl_response["Clusters"][0]['Tags'] #Append cluster tags to snapshot client.create_tags(ResourceName=arn,Tags=clustertags) #If cluster no longer exists print Exception and continue function except: print("Cluster already destroyed: no tags to be assigned") continue return "Function Complete"
这是我为检查每个快照的标签而编写的 lambda,如果没有标签,则从集群中提取标签并添加它们。如果集群已经被销毁但快照仍然存在,则例外。
推荐阅读
- javascript - 在另一个节点 js 服务器之前添加登录节点服务器
- python - 如何使用 Python 创建屏幕截图 Motion JPEG 流媒体服务器?
- c++ - C++ - 以特定方式对向量中的字符串进行排序
- reactjs - React tiliio 可编程视频切换摄像头不工作
- c# - OpenIdConnectProtocolInvalidNonceException。用户仍然可以在 AuthenticationFailed 通知上进行身份验证吗?
- java - 以随机顺序访问数组中的每个值
- java - 如何使用“@”(注释)在变量名称中签名创建变量?
- php - 我的变量有问题吗?
- python - 如何从“cats_vs_dogs”张量流数据集中查看图像
- html - 即使使用 flexbox 和显式最大高度,div 也会超出这些限制