Last active
September 18, 2022 14:01
-
-
Save nixjobin/2f860ba9a4a5022eaff7d1799224cecb to your computer and use it in GitHub Desktop.
AWS - Scheduled shutdown and startup of the EC2 instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Youtube video - https://www.youtube.com/watch?v=jkn459MBNpo | |
#LAMBDA Stop instance index.js | |
const AWS = require('aws-sdk'); | |
exports.handler = (event, context, callback) => { | |
const ec2 = new AWS.EC2({ region: event.instanceRegion }); | |
ec2.stopInstances({ InstanceIds: [event.instanceId] }).promise() | |
.then(() => callback(null, `Successfully stopped ${event.instanceId}`)) | |
.catch(err => callback(err)); | |
}; | |
# LAMBDA Start instance index.js | |
const AWS = require('aws-sdk'); | |
exports.handler = (event, context, callback) => { | |
const ec2 = new AWS.EC2({ region: event.instanceRegion }); | |
ec2.startInstances({ InstanceIds: [event.instanceId] }).promise() | |
.then(() => callback(null, `Successfully started ${event.instanceId}`)) | |
.catch(err => callback(err)); | |
}; | |
#test / JSON script for schedule | |
{ | |
"instanceRegion": "us-east-1", | |
"instanceId": "i-06c8946147bf2f235" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
works thx :)