Skip to content

Instantly share code, notes, and snippets.

View ashutoshkarna03's full-sized avatar
🎯
Focusing

ashutoshkarna03

🎯
Focusing
View GitHub Profile
db_dict = {
'1':'a',
'2':'b',
'3':'c',
'4':'d'
}
ans_dict = {
'3':'c',
'4':'a'
import boto3
# create client for ec2 service and pass aws_access_key_id and aws_secret_access_key as parameter
client = boto3.client('ec2', region_name='us-east-1', aws_access_key_id= 'AWS_ACCESS_KEY_ID',
aws_secret_access_key= 'AWS_SECRET_ACCESS_KEY' )
# create a dictionary with names of databases or instances as key and their volume ids as value
volumes_dict = {
'database-1' : 'volume-id-1',
'database-2' : 'volume-id-2',
'database-3' : 'volume-id-3',
@ashutoshkarna03
ashutoshkarna03 / delete_snapshots.py
Created August 16, 2019 13:04
Code to delete aws snapshots
import boto3
# create client for ec2 service and pass aws_access_key_id and aws_secret_access_key as parameter
client = boto3.client('ec2', region_name='us-east-1', aws_access_key_id= 'AWS_ACCESS_KEY_ID',
aws_secret_access_key= 'AWS_SECRET_ACCESS_KEY' )
# dictionary with names of databases or instances as key and their volume ids as value that we had created previously
volumes_dict = {
'database-1' : 'volume-id-1',
'database-2' : 'volume-id-2',
'database-3' : 'volume-id-3',
version: '3'
services:
redis:
image: redis:latest
ports:
- 6379:6379
volumes:
- ./config/redis.conf:/redis.conf
command: [ "redis-server", "/redis.conf" ]
import redis
# connect to redis
client = redis.Redis(host='localhost', port=6379)
# set a key
client.set('test-key', 'test-value')
# get a value
value = client.get('test-key')
import boto3
from pprint import pprint
import dotenv
import os
# load the environment variables
dotenv.load_dotenv()
# create boto3 client for ec2
client = boto3.client('ec2',
# create a list where the volume ids of unused volumes will be stored
volumes_to_delete = list()
# call describe_volumes() method of client to get the details of all ebs volumes in given region
# if you have large number of volumes then get the volume detail in batch by using nextToken and process accordingly
volume_detail = client.describe_volumes()
# process each volume in volume_detail
if volume_detail['ResponseMetadata']['HTTPStatusCode'] == 200:
for each_volume in volume_detail['Volumes']:
# proceed for deletion
for each_volume_id in volumes_to_delete:
try:
print("Deleting Volume with volume_id: " + each_volume_id)
response = client.delete_volume(
VolumeId=each_volume_id
)
except Exception as e:
print("Issue in deleting volume with id: " + each_volume_id + "and error is: " + str(e))
version: '3'
services:
mysqldb:
image: mysql:8.0.2
environment:
MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD
MYSQL_DATABASE: MYSQL_DATABASE
ports:
FROM node:10
# Create app directory
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
# Bundle app source