This file contains 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
db_dict = { | |
'1':'a', | |
'2':'b', | |
'3':'c', | |
'4':'d' | |
} | |
ans_dict = { | |
'3':'c', | |
'4':'a' |
This file contains 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 | |
# 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', |
This file contains 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 | |
# 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', |
This file contains 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
version: '3' | |
services: | |
redis: | |
image: redis:latest | |
ports: | |
- 6379:6379 | |
volumes: | |
- ./config/redis.conf:/redis.conf | |
command: [ "redis-server", "/redis.conf" ] |
This file contains 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 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') |
This file contains 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 | |
from pprint import pprint | |
import dotenv | |
import os | |
# load the environment variables | |
dotenv.load_dotenv() | |
# create boto3 client for ec2 | |
client = boto3.client('ec2', |
This file contains 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
# 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']: |
This file contains 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
# 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)) |
This file contains 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
version: '3' | |
services: | |
mysqldb: | |
image: mysql:8.0.2 | |
environment: | |
MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD | |
MYSQL_DATABASE: MYSQL_DATABASE | |
ports: |
This file contains 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
FROM node:10 | |
# Create app directory | |
WORKDIR /usr/src/app | |
COPY package*.json ./ | |
RUN npm install | |
# Bundle app source |
OlderNewer