我正在尝试使用 python (boto3) 测试从快照中恢复 Neptune 实例。长话短说,我们希望每天使用自动化来启动和删除 Dev 实例。
还原时,我的还原似乎只创建集群而不创建附加实例。一旦集群启动并添加到集群,我也尝试过创建一个实例,但这也不起作用。(参考:client.create_db_instance)
我的代码如下,获取最新的快照。使用该变量创建集群,以便最新数据存在。
import boto3
client = boto3.client('neptune')
response = client.describe_db_cluster_snapshots(
DBClusterIdentifier='neptune',
MaxRecords=100,
IncludeShared=False,
IncludePublic=False
)
snaps = response['DBClusterSnapshots']
snaps.sort(key=lambda c: c['SnapshotCreateTime'], reverse=True)
latest_snapshot = snaps[0]
snapshot_ID = latest_snapshot['DBClusterSnapshotIdentifier']
print("Latest snapshot: " + snapshot_ID)
db_response = client.restore_db_cluster_from_snapshot(
AvailabilityZones=['us-east-1c'],
DBClusterIdentifier='neptune-test',
SnapshotIdentifier=snapshot_ID,
Engine='neptune',
Port=8182,
VpcSecurityGroupIds=['sg-randomString'],
DBSubnetGroupName='default-vpc-groupID'
)
time.sleep(60)
db_instance_response = client.create_db_instance(
DBName='neptune',
DBInstanceIdentifier='brillium-neptune',
DBInstanceClass='db.r4.large',
Engine='neptune',
DBSecurityGroups=[
'sg-string',
],
AvailabilityZone='us-east-1c',
DBSubnetGroupName='default-vpc-string',
BackupRetentionPeriod=7,
Port=8182,
MultiAZ=False,
AutoMinorVersionUpgrade=True,
PubliclyAccessible=False,
DBClusterIdentifier='neptune-test',
StorageEncrypted=True
)
该文档根本没有多大帮助。它非常擅长提供基本创建所需的变量,但不能提供实际实例。如果我尝试使用相同的集群名称创建一个实例,它要么会出错,要么会创建一个具有相同名称并附加“-1”的新集群。