0
我是Python和Lambda的新手,我試圖獲得所有區域的in-use
卷的列表。AWS Lambda博託describe_volumes
from datetime import datetime, date
import boto3
def lambda_handler(event, context):
ec2 = boto3.client('ec2')
# Get list of regions
regions = ec2.describe_regions().get('Regions',[])
# Iterate over regions
for region in regions:
print "Looking at region %s " % region['RegionName']
reg=region['RegionName']
# Connect to region
ec2 = boto3.client('ec2',region_name=reg)
# Get all in-use volumes
volumes = ec2.describe_volumes(Filters=[{'Name': 'status', 'Values': ['in-use']}])
for volume in volumes:
print "Looking at volume %s" % volume['VolumeId']
我不斷收到以下錯誤,無法找出原因:
String indices must be integers, not str: TypeError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 22, in lambda_handler
print "Looking at volume %s" % volume['VolumeId']
TypeError: string indices must be integers, not str