下面是我使用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行失败。
"TypeError: string indices must be integers".
有谁能让我知道我在调用"restore_db_instance_from_db_snapshot"的键和值时哪里做错了吗?模块。
问题似乎是rdsinstances['DBInstance']
是dict
,但您试图迭代它,好像它是list
。