Skip to content

Instantly share code, notes, and snippets.

@PrashantBhatasana
Last active January 10, 2020 07:18
Show Gist options
  • Save PrashantBhatasana/5ec106feca1bb7489ada99e260d97f4d to your computer and use it in GitHub Desktop.
Save PrashantBhatasana/5ec106feca1bb7489ada99e260d97f4d to your computer and use it in GitHub Desktop.
This is lambda function with javascript language that stop ec2 instence.
// StopEC2Instance
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));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment