使用 AWS RDS API 復制快照時是否可以更改快照的識別符號?我正在使用 Boto3 撰寫要在 DR 場景中使用的 Lambda 函式。
我嘗試更改識別符號的原因是因為我想將當前日期添加到快照識別符號中,原因有兩個:
- 更容易識別快照的來源
- 需要不同的識別符號,以便我可以創建多個快照。我想到的一種解決方法是在復制最新版本之前洗掉最新的快照,但我想知道是否可以像通過管理那樣更改快照識別符號安慰。
我的代碼:
client = boto3.client("rds") #dr region
db_identifier = "test-database-dr"
# Get snapshot automated arn so we can create a manual copy
describe_snapshots = client.describe_db_snapshots(
SnapshotType= "shared",
IncludeShared=True,
)
db_arn = (describe_snapshots["DBSnapshots"][-1]["DBSnapshotArn"])
# Create a snapshot copy
copy_snapshot = client.copy_db_snapshot(
SourceDBSnapshotIdentifier=db_arn,
TargetDBSnapshotIdentifier=db_identifier,
KmsKeyId="xxx",
SourceRegion="xxx"
)
我得到的錯誤是:
botocore.errorfactory.DBSnapshotAlreadyExistsFault: An error occurred (DBSnapshotAlreadyExists) when calling the CopyDBSnapshot operation: Cannot create the snapshot because a snapshot with the identifier test-database-dr already exists.
uj5u.com熱心網友回復:
您需要將 設定TargetDBSnapshotIdentifier為不同的東西。
client = boto3.client("rds") #dr region
db_identifier = "test-database-dr-SOMETHING-DIFFERENT"
# Get snapshot automated arn so we can create a manual copy
describe_snapshots = client.describe_db_snapshots(
SnapshotType= "shared",
IncludeShared=True,
)
db_arn = (describe_snapshots["DBSnapshots"][-1]["DBSnapshotArn"])
# Create a snapshot copy
copy_snapshot = client.copy_db_snapshot(
SourceDBSnapshotIdentifier=db_arn,
TargetDBSnapshotIdentifier=db_identifier,
KmsKeyId="xxx",
SourceRegion="xxx"
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/346702.html
