Skip to content

Instantly share code, notes, and snippets.

View PrashantBhatasana's full-sized avatar
🎯
Focusing

Bhatasana Prashant PrashantBhatasana

🎯
Focusing
View GitHub Profile
resource "aws_launch_configuration" "this" {
name = "ECS-Instance-${var.environment}"
image_id = "${data.aws_ami.latest-ecs.id}"
instance_type = "m4.xlarge"
iam_instance_profile = "${aws_iam_instance_profile.ecs-instance-profile.id}"
root_block_device {
volume_type = "gp2"
volume_size = 100
delete_on_termination = true
var AWS = require('aws-sdk');
var url = require('url');
var https = require('https');
var util = require('util');
const p = require('phin');
var costexplorer = new AWS.CostExplorer();
const reqURL = process.env.Slack_Webhook_url;
@PrashantBhatasana
PrashantBhatasana / slack_notification_lambda_function.js
Last active April 17, 2020 09:39
This is the lambda function that send slack notification.
const AWS = require('aws-sdk');
var url = require('url');
var https = require('https');
var util = require('util');
const p = require('phin');
const reqURL = `https://hooks.slack.com/services/TBCSBJ5/50117HG5HFV/hnfnDN78KJNH56RFVds`;
async function notifySlack() {
@PrashantBhatasana
PrashantBhatasana / terminateInstances_lambda_function.js
Created March 23, 2020 06:24
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));
@PrashantBhatasana
PrashantBhatasana / terminate_instances_lambda_function.py
Created March 23, 2020 06:17
This is lambda function with python language that Terminate ec2 instence.
import boto3
import time
region = 'us-XXXX-2'
instances = ['i-XXXXXXXXXXXXXXXX']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.terminate_instances(InstanceIds=instances)
print 'Terminate your instances: ' + str(instances)
@PrashantBhatasana
PrashantBhatasana / startInstances_lambda_function.js
Last active January 10, 2020 07:19
This is lambda function with javascript language that start ec2 instence.
// StartEC2Instance
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));
@PrashantBhatasana
PrashantBhatasana / stopInstances_lambda_function.js
Last active January 10, 2020 07:18
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));
@PrashantBhatasana
PrashantBhatasana / create_instances_lambda_function.py
Last active May 26, 2021 14:20
This is lambda function with python language that create ec2 instence.
import os
import boto3
AMI = os.environ['AMI']
INSTANCE_TYPE = os.environ['INSTANCE_TYPE']
KEY_NAME = os.environ['KEY_NAME']
SUBNET_ID = os.environ['SUBNET_ID']
REGION = os.environ['REGION']
ec2 = boto3.client('ec2', region_name=REGION)
@PrashantBhatasana
PrashantBhatasana / stop_instances_lambda_function.py
Last active January 10, 2020 07:16
This is lambda function with python language that stop ec2 instence.
import boto3
import time
region = 'us-XXXX-2'
instances = ['i-XXXXXXXXXXXXXXXX']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=instances)
print 'started your instances: ' + str(instances)
@PrashantBhatasana
PrashantBhatasana / start_instances_lambda_function.py
Last active January 10, 2020 07:16
This is lambda function with python language that start ec2 instence.
import boto3
import time
region = 'us-XXXX-2'
instances = ['i-XXXXXXXXXXXXXXXX']
def lambda_handler(event, context):
ec2 = boto3.client('ec2', region_name=region)
ec2.start_instances(InstanceIds=instances)
print 'started your instances: ' + str(instances)