View on GitHub

Start-stop-ec2-instances across all regions

NODEJS : Start-Stop-EC2-Instances Across All Regions Automatically using Lambda

Download this project as a .zip file Download this project as a tar.gz file

Start-Stop-EC2-Instances_Across_All_Regions

Two Lambda functions are needed to run Start and stop.js Scripts.

Start function: Instructions

Stop function: Instructions


a.) Lambda function to Start Instances (start.js):

The Script runs across all AWS regions and makes API Calls DescribeInstances() and StartInstances(), based on applied filters.

Steps:

Tags:

Required IAM Roles for Lambda Function:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "MyStatementId",
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeInstances",
                "ec2:StopInstances",
                "ec2:StartInstances",
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}

b.) Lambda function to Stop Instances (stop.js):

The stop.js script shuts down all EC2 instances across all regions. Based on requirements cron job can be modified to shut down instances. Instructions are same as Starting Instances, except for the tags.

For Stop-instances function, I have used following Key-pair Tag:
 Key: stop 
 Value: StopWeekDays

Use Same IAM role for this Lambda function also.