亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 AWS LAMBDA 刪除舊的手動集群 Snaphots RDS

使用 AWS LAMBDA 刪除舊的手動集群 Snaphots RDS

PHP
Cats萌萌 2023-11-09 14:58:16
在我的 AWS Lambda 的 python 代碼下方,我想使用它刪除舊的手動 RDS 快照,但它仍然無法正常工作,我需要幫助來調試和更正此 lambda 腳本。非常感謝。import boto3from os import getenvimport datetimefrom datetime import dateclient = 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()
查看完整描述

1 回答

?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

您的代碼看起來不錯,但您應該刪除子函數: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"])



查看完整回答
反對 回復 2023-11-09
  • 1 回答
  • 0 關注
  • 165 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號