微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用AWS LAMBDA删除旧的手动Cluster Snaphots RDS

如何解决使用AWS LAMBDA删除旧的手动Cluster Snaphots RDS

在我的AWS Lambda的python代码下面,我想通过使用它删除OLD MANUAL RDS SNAPSHOTS,它仍然无法正常工作,我需要帮助来调试和更正此Lambda脚本。非常感谢。

import boto3
from os import getenv
import datetime
from datetime import date
client = boto3.client('rds')
ClientName = getenv('CLIENT_NAME')
today = date.today()

def lambda_handler(event,context):
    delete_db_cluster_snapshot():
    snapshots_marker = ""
    while snapshots_marker != None:
        snapshots = client.describe_db_cluster_snapshots(Marker=snapshots_marker)
        
        if 'Marker' in snapshots:
            snapshots_marker = snapshots['Marker']
        else:
            snapshots_marker = None
            
        for snapshot in snapshots['DBClusterSnapshots']:
            if snapshot["Snapshottype"] == "manual" and ClientName in snapshot["DBClusterIdentifier"] and snapshot ["SnapshotCreateTime"].date() < today:
                client.delete_db_cluster_snapshot(DBClusterSnapshotIdentifier=snapshot["DBClusterSnapshotIdentifier"])
                
delete_db_cluster_snapshot()

解决方法

您的代码看起来不错,但是您应该删除delete_db_cluster_snapshot()子功能:

import boto3
from os import getenv
import datetime
from datetime import date

client = boto3.client('rds')
ClientName = getenv('CLIENT_NAME')
today = date.today()

def lambda_handler(event,context):
    snapshots_marker = ""
    while snapshots_marker != None:
        snapshots = client.describe_db_cluster_snapshots(Marker=snapshots_marker)
        
        if 'Marker' in snapshots:
            snapshots_marker = snapshots['Marker']
        else:
            snapshots_marker = None
            
        for snapshot in snapshots['DBClusterSnapshots']:
            if snapshot["SnapshotType"] == "manual" and ClientName in snapshot["DBClusterIdentifier"] and snapshot ["SnapshotCreateTime"].date() < today:
                client.delete_db_cluster_snapshot(DBClusterSnapshotIdentifier=snapshot["DBClusterSnapshotIdentifier"])

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。