RDS快照在AWS中使用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快照还原DB实例,但是在第10行中,打印输出在第10行中失败
。“ TypeError:字符串索引必须是整数”。
可以让我知道我在调用“ restore_db_instance_from_db_snapshot”模块的键和值时做错了什么。
Here is my code to restore the rds instance from rds snapshot using python boto3
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'])
My Code was able to restore the db instance from RDS Snapshot but the print output is failing at line 10.
"TypeError: string indices must be integers".
Can any one please let me know where I am doing wrong in calling the key and value for "restore_db_instance_from_db_snapshot" module.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题似乎是
rdsinstances ['dbinstance']
是dict
,但是您正在尝试迭代它,就像它是list 。
The issue appears to be that
rdsinstances['DBInstance']
is andict
, but you are trying to iterate over it as though it is alist
.