Skip to content

Instantly share code, notes, and snippets.

View ashutoshkarna03's full-sized avatar
🎯
Focusing

ashutoshkarna03

🎯
Focusing
View GitHub Profile
def migrate(instances_list):
# create boto3 client for ec2 for both source and destination region
client_src = boto3.client('ec2', region_name=os.getenv('SOURCE_REGION'))
client_des = boto3.client('ec2', region_name=os.getenv('DESTINATION_REGION'))
# create ec2 resource
ec2 = boto3.resource('ec2', region_name=os.getenv('DESTINATION_REGION'))
total_instances = len(instances_list)
# iterate through list of intances in source region to be migrated
for n, instance in enumerate(instances_list):
try:
def launch_instance(image_id, instance_id, client_src, client_des, ec2_resource_des):
# create waiter for destination instance to check if instance status is `ok`
waiter = client_des.get_waiter('instance_status_ok')
# get the source instance details needed for launching the instance
instance_detail = get_instance_details(instance_id, client_src)
# launch instance using create_instances() method of ec2 resource
try:
response = ec2_resource_des.create_instances(
ImageId=image_id,
InstanceType=instance_detail['instance_type'],
def copy_image_to_destination_region(image_id, instance_id, client):
waiter = client.get_waiter('image_available')
source_region = os.getenv('SOURCE_REGION')
# call copy_image to copy the AMI from source region to destination
response = client.copy_image(
Description='Copied image of instance: ' + instance_id + ' from region: ' + source_region,
Name='new image of instance ' + instance_id,
SourceImageId=image_id,
SourceRegion=source_region,
)
def create_image_of_instance(instance_id, client):
waiter = client.get_waiter('image_available')
# call create_image to create AMI of given instance
response = client.create_image(InstanceId=instance_id, Name="latest-image-of-" + instance_id)
print('Creating image, this may take few minutes...')
waiter.wait(ImageIds=[response['ImageId']], DryRun=False)
return response['ImageId']
# create boto3 client for ec2 for both source and destination region
client_src = boto3.client('ec2', region_name=os.getenv('SOURCE_REGION'))
client_des = boto3.client('ec2', region_name=os.getenv('DESTINATION_REGION'))
# create ec2 resource
ec2 = boto3.resource('ec2', region_name=os.getenv('DESTINATION_REGION'))
# create boto3 client for ec2 for both source and destination region
client_src = boto3.client('ec2', region_name=os.getenv('SOURCE_REGION'))
client_des = boto3.client('ec2', region_name=os.getenv('DESTINATION_REGION'))
# create ec2 resource
ec2 = boto3.resource('ec2', region_name=os.getenv('DESTINATION_REGION'))
def stop_instance(instance_id, client):
waiter = client.get_waiter('instance_stopped')
# call stop_instances to stop the instance
response = client.stop_instances(InstanceIds=[instance_id], DryRun=False)
# waiter waits until the stop operation is complete
print('Stopping instance, this may take few minutes...')
waiter.wait(InstanceIds=[instance_id,], DryRun=False)
return dict(success=True)
function initSparkline() {
$(".sparkline").each(function () {
var a = $(this);
a.sparkline("html", a.data())
})
}
function skinChanger() {
$(".choose-skin li").on("click", function () {
var a = $("body"),
'use strict';
const crypto = require('crypto');
const pool = require('./pg')
// const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
// this is always stored in env file but for demonstration purpose, I have added it here
const ENCRYPTION_KEY = "bPeShVmYq3s6v9y$B&E)H@McQfTjWnZr"
const IV_LENGTH = 16; // For AES, this is always 16
# This workflow will build and push a new container image to Amazon ECR
#
# To use this workflow, you will need to complete the following set-up steps:
#
# 1. Create an ECR repository to store your images.
# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`.
# Replace the value of `ECR_REPOSITORY` in the workflow below with your repository's name.
# Replace the value of `aws-region` in the workflow below with your repository's region.
on: