python-3.x - 复制时更改快照名称的 AWS RDS API 命令
问题描述
使用 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.
解决方案
您需要将 设置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"
)
推荐阅读
- javascript - 池请求与批处理请求
- cmake - cmake 更改 gtest 的编译器
- java - @Scheduled 作业阻塞 Quartz 作业
- macos - 构建 golang 应用程序导致“TARGET_OS_IPHONE”未定义错误
- ckeditor - 标签的ckeditor样式集-在a中渲染svg
- javascript - 如何在页面重新加载超过 10 像素时激活颜色更改导航
- android - 从另一个 BottomSheetDialogFragment 打开另一个 BottomSheetDialogFragment
- bash - 将参数传递给 bash 中的命令
- amazon-web-services - Aws Terraform - 跨账户连接
- swiftui - 如何同时关闭多个堆叠的 SwiftUI 模态/表格?