Загрузка страницы

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

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/knowledge-center/start-stop-lambda-cloudwatch/

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))

Видео How to Automatically Stop/Start EC2 instances using AWS Lambda| Cloudwatch Events Scheduler канала Tech Nest
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
30 июня 2020 г. 1:43:50
00:12:23
Яндекс.Метрика