-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_instance.py
More file actions
27 lines (25 loc) 路 778 Bytes
/
Copy pathstart_instance.py
File metadata and controls
27 lines (25 loc) 路 778 Bytes
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
# # Libraries
import os
import time
import json
import boto3
import logging
# # Default Values
instance_id = os.environ['InstanceId']
logging.basicConfig(level=logging.INFO)
ec2 = boto3.client('ec2', region_name='us-east-1')
# # Lambda Function
def handler(event, context):
ec2.start_instances(InstanceIds=[instance_id])
time.sleep(5)
reservations = ec2.describe_instances(InstanceIds=[instance_id]).get("Reservations")
for reservation in reservations:
for instance in reservation['Instances']:
# print(instance.get("PublicIpAddress"))
logging.info(instance.get("PublicIpAddress"))
ip = instance.get("PublicIpAddress")
# return str(ip)
return {
'statusCode': 200,
'body': json.dumps(ip)
}