我正在尝试使用 boto3 检索标签,但我经常遇到 ListIndex 超出范围错误。
我的代码:
rds = boto3.client('rds',region_name='us-east-1')
rdsinstances = rds.describe_db_instances()
for rdsins in rdsinstances['DBInstances']:
rdsname = rdsins['DBInstanceIdentifier']
arn = "arn:aws:rds:%s:%s:db:%s"%(reg,account_id,rdsname)
rdstags = rds.list_tags_for_resource(ResourceName=arn)
if 'MyTag' in rdstags['TagList'][0]['Key']:
print "Tags exist and the value is:%s"%rdstags['TagList'][0]['Value']
我的错误是:
Traceback (most recent call last):
File "rdstags.py", line 49, in <module>
if 'MyTag' in rdstags['TagList'][0]['Key']:
IndexError: list index out of range
我还尝试通过指定范围来使用 for 循环,它似乎也不起作用。
for i in range(0,10):
print rdstags['TagList'][i]['Key']
任何帮助表示赞赏。谢谢!