【发布时间】:2022-01-01 00:22:44
【问题描述】:
我正在尝试使用 Lambda 停止我的 RDS 集群,并使用下面显示的 python 代码来定位集群标签, 但是,在尝试创建 CloudFormation 堆栈时,AWS 告诉我 YAML 格式不正确。
例如,它告诉 Key = 'True' 格式不正确。 如果我删除那段代码,它会告诉我下一段代码,client = boto3.client('rds') 格式也不正确。
我已将此代码放入在线 python 验证器中,但没有报告任何问题。 有人能帮忙吗?谢谢
Tag = 'AutoPower'
Key = 'True'
client = boto3.client('rds')
response = client.describe_db_cluster()
for resp in response['DBCluster']:
db_cluster_arn = resp['DBClusterArn']
response = client.list_tags_for_resource(ResourceName=db_cluster_arn)
for tags in response['TagList']:
if tags['Key'] == str(Key) and tags['Value'] == str(Tag):
status = resp['DBClusterStatus']
ClusterID = resp['DBClusterIdentifier']
print(InstanceID)
if status == 'available':
print("shutting down %s " % ClusterID)
client.stop_db_cluster(DBClusterIdentifier=ClusterID)
# print ("Do something with it : %s" % db_instance_arn)
elif status == 'stopped':
print("starting up %s " % ClusterID)
client.start_db_cluster(DBClusterIdentifier=ClusterID)
else:
print("The database is " + status + " status!")
【问题讨论】:
-
为什么会被解析为 Yaml?
-
python 是 Lambda 函数用来停止 RDS 集群的内联代码的一部分
-
我建议您编辑问题标题以包含更多关键字,例如 lambda aws...,这将提高问题的质量和范围。
-
如果我错了,请纠正我,您正在尝试使用 cloudFormation 创建一个 lambda,它将执行一些 RDS 活动。如果您遇到“YAML”验证问题,请分享 yaml/脚本文件而不是 python 代码。
标签: python amazon-web-services amazon-cloudformation