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
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 |
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
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; |
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
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() { |
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
// 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)); |
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
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) |
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
// 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)); |
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
// 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)); |
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
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) |
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
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) |
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
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) |