繁体   English   中英

使用 Python BOTO3 在 AWS 中恢复 RDS 快照

[英]RDS Snapshot Restore in AWS with Python BOTO3

这是我使用 python boto3 从 rds 快照恢复 rds 实例的代码

import boto3
x=input('Please enter the RDS Instance Name :')
z=input('Please enter the RDS Snapshot Name :')
y=input('Please enter the RDS Instance Class:')
a=input('Please enter the RDS Instance Subnet Group Name:')
client = boto3.client('rds', region_name='xxxxxxx')

rdsinstances = client.restore_db_instance_from_db_snapshot(DBInstanceIdentifier=x.strip(),DBSnapshotIdentifier=z.strip(),DBInstanceClass=y.strip(),DBSubnetGroupName=a.strip())
for i in rdsinstances['DBInstance']:
 print('Instance_name:' + i['DBInstanceIdentifier'])
 print('DB_Instance_Status:' + i['DBInstanceStatus'])
 print('DB_Instance_Class:' + i['DBInstanceClass'])
 print('DB_Subnet_Group:' + i['DBSubnetGroupName'])

我的代码能够从 RDS 快照恢复数据库实例,但打印 output 在第 10 行失败。

"TypeError: string indices must be integers".

谁能让我知道我在调用“restore_db_instance_from_db_snapshot”模块的键和值时做错了什么。

问题似乎是rdsinstances['DBInstance']是一个dict ,但你试图迭代它,就好像它是一个list

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM