Skip to content

Instantly share code, notes, and snippets.

import boto3
import json
def lambda_handler(event, context):
print("Received event: " + json.dumps(event))
if event['detail']['eventName'] == 'ModifyInstanceAttribute' and 'instanceType' in event['detail']['requestParameters']:
instance_id = event['detail']['requestParameters']['instanceId']
instance_type = event['detail']['requestParameters']['instanceType']['value']
cw = boto3.client('cloudwatch')
alarms = cw.describe_alarms()
#!/bin/bash
# Prompt the user to enter the instance ID to check for
read -p "Enter the instance ID to check for: " INSTANCE_ID
# Get a list of all load balancer ARNs in the current AWS account
LB_ARNS=$(aws elbv2 describe-load-balancers --query "LoadBalancers[].LoadBalancerArn" --output text)
# Loop through each load balancer ARN and check if the instance is registered with any target groups
for LB_ARN in $LB_ARNS
import boto3
import json
import time
ssm = boto3.client('ssm')
def lambda_handler(event, context):
# Check if the event is a ModifyInstanceAttribute event and has an instance-type change
if event['detail']['eventName'] == 'ModifyInstanceAttribute' and \
event['detail']['requestParameters'].get('instanceType') is not None:
{
"source": ["aws.ec2"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventSource": ["ec2.amazonaws.com"],
"eventName": ["ModifyInstanceAttribute"]
}
}
{
"metrics": {
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
"metrics_collected": {
"LogicalDisk": {
import json
import urllib.parse
import boto3
print('Loading function')
s3 = boto3.client('s3')
mt = boto3.client('mediatailor')
@hetul99
hetul99 / docker_notes.txt
Last active September 11, 2020 04:41 — forked from sd031/docker_notes.txt
Detailed Docker notes from Docker Deep dive course
Course url: https://linuxacademy.com/containers/training/course/name/docker-deep-dive-part-1
==================== All Docker Command While Learning Docker =========================
Get a list of all of the Docker commands:
docker -h
====== Attaching to Container , run in background , name it ==========
Create a container and attach to it:
@hetul99
hetul99 / PruneSnapShots.py
Created August 6, 2020 10:14
This will be followed by the CreateSnapShot lambda function. As CreateSnapShot will keep on making the backups( if you have it scheduled for everyday or every month) but won't delete it. This function will delete the snapshot and keep only the latest 3 copies of the snapshot
from datetime import datetime
import boto3
def lambda_handler(event, context):
account_id = boto3.client('sts').get_caller_identity().get('Account')
ec2 = boto3.client('ec2')
regions = [region['RegionName']
for region in ec2.describe_regions()['Regions']]
#Iterate over each Region
@hetul99
hetul99 / CreateSnapShot.py
Last active August 6, 2020 10:05
This snapshot will keep on creating the snaps of EC2 instances having the TAGS as "backup"="true". But you have to schedule when to take snaps in the CloudWatch Event Rule. Also this will keep on creating the snap so REMEMBER to implement PruneSnapShots lambda function when you use this CreateSnapShot function to delete the snapshot created and …
from datetime import datetime
import boto3
def lambda_handler(event, context):
ec2_client = boto3.client('ec2')
regions = [region['RegionName']
for region in ec2_client.describe_regions()['Regions']]
for region in regions:
import boto3
def lambda_handler(event, context):
#Get list of Regions
ec2_client = boto3.client('ec2')
regions = [region['RegionName']
for region in ec2_client.describe_regions()['Regions']]
#Iterate over each Region
for region in regions: