-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode
29 lines (21 loc) · 799 Bytes
/
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import json
import boto3
ec2list = []
def lambda_handler(event, context):
# Get list of regions
ec2 = boto3.client('ec2')
regions = ec2.describe_regions().get('Regions',[] )
# Iterate over regions
for region in regions:
print ("* Checking region -- %s " % region['RegionName'])
reg=region['RegionName']
client = boto3.client('ec2', region_name=reg)
response = client.describe_instances()
for reservation in response["Reservations"]:
for instance in reservation["Instances"]:
print (" ---- Instance %s in %s" % (instance['InstanceId'], region['RegionName']))
ec2list.append(instance['InstanceId'])
return {
"statusCode": 200,
"body": ec2list
}