Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PrashantBhatasana/c68b61373b8f0497c82a1cdb2758631a to your computer and use it in GitHub Desktop.
Save PrashantBhatasana/c68b61373b8f0497c82a1cdb2758631a to your computer and use it in GitHub Desktop.
This is lambda function with javascript language that terminate ec2 instence.
// StopEC2Instance
const AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
const ec2 = new AWS.EC2({ region: event.instanceRegion });
ec2.terminateInstances({ 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