Перейти к содержимому

How to Automatically Stop/Start EC2 instances using AWS Lambda| Cloudwatch Events Scheduler

Sumi P

0:00 / 0:00

How to Automatically Stop/Start EC2 instances using AWS Lambda| Cloudwatch Events Scheduler

43 801 просмотр · 6 лет назад
Sumi P
2,27 тыс. подписчиков
43 801 просмотр · 6 лет назад
In this video we have walked through to Start/Stop instance using Lambda function and manage using Cloudwatch Events . Refer Link : https://aws.amazon.com/premiumsupport... Please Find the Scripts To Create IAM policy using JSON policy editor:- { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": [ "ec2:Start*", "ec2:Stop*" ], "Resource": "*" } ] } Stop the instances:- import boto3 region = 'us-west-1' instances = ['i-12345cb6de4f78g9h', 'i-08ce9b2d7eccf6d26'] ec2 = boto3.client('ec2', region_name=region) def lambda_handler(event, context): ec2.stop_instances(InstanceIds=instances) print('stopped your instances: ' + str(instances)) Start the instances:- import boto3 region = 'us-west-1' instances = ['i-12345cb6de4f78g9h', 'i-08ce9b2d7eccf6d26'] ec2 = boto3.client('ec2', region_name=region) def lambda_handler(event, context): ec2.start_instances(InstanceIds=instances) print('started your instances: ' + str(instances))