0% found this document useful (0 votes)
5 views9 pages

AWS Instance Stop and Start Documents

Uploaded by

sivaramkcloud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

AWS Instance Stop and Start Documents

Uploaded by

sivaramkcloud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Instance Stop and Start Documents

AWS Lambda
As per AWS “AWS Lambda lets you run code without provisioning or managing
servers. You pay only for the compute time you consume.
With Lambda, you can run code for virtually any type of application or backend
service – all with zero administration. Just upload your code and Lambda takes care of
everything required to run and scale your code with high availability. You can set up
your code to automatically trigger from other AWS services or call it directly from
any web or mobile app.
AWS EC2
As per AWS “Amazon Elastic Compute Cloud (Amazon EC2) is a web service that
provides secure, resizable compute capacity in the cloud. It is designed to make web-
scale cloud computing easier for developers.”
Amazon EC2’s simple web service interface allows you to obtain and configure
capacity with minimal friction. It provides you with complete control of your
computing resources and lets you run on Amazon’s proven computing environment.
Pre-Requirements
1) Create a custom AWS Identity and Access Management (IAM) policy and
execution role for your Lambda function.
2) Create Lambda functions that stop and start your EC2 instances.
3) Test your Lambda functions
4) Create Cloud Watch Events rules that trigger your function on a schedule. For
example, you could create a rule to stop your EC2 instances at night, and
another to start them again in the morning.
IAM Policy Creation
[Link] PolicesCreate Policy
[Link] Select JSON and paste the below code

{
"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": "*"
}
]
}
Note:
[Link]
cloudwatch/
Review Policy and Type the Name InstancesStopStart-Policy

2) IAM Role Creation


Select RoleCreate Role
Select the AWS Service and select LambdaNext:Permission

Find the recently create the InstancesStopStart-Policy


Type the Role Name:InstanceStopStart-Role and Select Create role

3)Lambda Function creation(Stop and Start)


To create the InstancesStop policy

Select Function and select create function


Create the functionAuthor from scratchType the function name:
InstanceStop-PolicySelect run time: Python 3.7Permission: Select change default
execution role Use an existing roleFind InstanceStopandStart-PolicyCreate
functionAnd update the InstanceStop code and Save or Deploy

import boto3
region = 'ap-southeast-1'
instances = ['i-08d15778963a11c47']
ec2 = [Link]('ec2', region_name=region)

def lambda_handler(event, context):


ec2.stop_instances(InstanceIds=instances)
print('stopped your instances: ' + str(instances))

InstanceStart Policy
Create the functionAuthor from scratchType the function name: InstanceStop-
PolicySelect run time: Python 3.7Permission: Select change default execution
role Use an existing roleFind InstanceStopandStart-PolicyCreate
functionAnd update the InstanceStop code and Save or Deploy
import boto3
region = 'ap-southeast-1'
instances = ['i-08d15778963a11c47']
ec2 = [Link]('ec2', region_name=region)

def lambda_handler(event, context):


ec2.start_instances(InstanceIds=instances)
print('started your instances: ' + str(instances))

4)CloudWatch: Cron schedule


Select CloudWatch and create the Rules:
Instance Stop Schedule:

Instance Stop every day Run at 12:15 pm (UTC)


Refer Notes:
[Link]
Select Configure details

Instance Start every day Run at 10:45 AM (UTC)


Instance Start Schedule:

You might also like