RDS快照在AWS中使用Python Boto3

发布于 2025-01-24 18:54:11 字数 939 浏览 0 评论 0原文

这是我的代码使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为你鎻心 2025-01-31 18:54:11

问题似乎是rdsinstances ['dbinstance']dict,但是您正在尝试迭代它,就像它是list 。

The issue appears to be that rdsinstances['DBInstance'] is an dict, but you are trying to iterate over it as though it is a list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文