Skip to content

Instantly share code, notes, and snippets.

View arbabnazar's full-sized avatar
🏠
Working from home

Arbab Nazar arbabnazar

🏠
Working from home
View GitHub Profile
@arbabnazar
arbabnazar / ec2_info_retriever.py
Created January 20, 2022 09:44 — forked from dastergon/ec2_info_retriever.py
A basic boto3 based tool for retrieving information from running EC2 instances.
from collections import defaultdict
import boto3
"""
A tool for retrieving basic information from the running EC2 instances.
"""
# Connect to EC2
ec2 = boto3.resource('ec2')
aws s3 ls s3://my-prod/directory --recursive --human-readable --summarize --profile aws-profile
aws s3 ls --summarize --human-readable --recursive s3://my-prod/* --profile aws-profile
aws s3 ls s3://my-prod --recursive --human-readable --summarize --profile aws-profile
aws s3 ls --profile aws-profile s3://my-prod --recursive | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}'
#Get the list of all the queues
rabbitmqadmin -f tsv --vhost=/ --username=RABBITMQ_USER --password=RABBITMQ_PASSWORD -q list queues name > file.txt
#Remove all the queues
while read -r name; do rabbitmqadmin --vhost=/ --username=RABBITMQ_USER --password=RABBITMQ_PASSWORD -q delete queue name="${name}"; done < file.txt
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 -days 1024 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
@arbabnazar
arbabnazar / deregister-task-definitions.sh
Created April 19, 2021 16:56 — forked from jen20/deregister-task-definitions.sh
Script to deregister all ECS Task Definitions in a given region
#!/usr/bin/env bash
get_task_definition_arns() {
aws ecs list-task-definitions --region ${AWS_REGION} \
| jq -M -r '.taskDefinitionArns | .[]'
}
delete_task_definition() {
local arn=$1

Convert the public key into specify key format (PKCS8)

ssh-keygen -f ~/.ssh/id_rsa.pub -e -m PKCS8 > ~/.ssh/id_rsa.pem

Using the public PKCS8 file to encrypt a string

echo "sometext" | openssl rsautl -encrypt -pubin -inkey ~/.ssh/id_rsa.pem > ~/encrypted-file.txt

OR file

@arbabnazar
arbabnazar / Java 8 PPA
Last active February 1, 2021 11:25
Java 8 working till today
sudo add-apt-repository ppa:ts.sch.gr/ppa
sudo apt-get update
sudo apt-get install oracle-java8-installer
@arbabnazar
arbabnazar / replace_ecs_cluster_instances.py
Created December 3, 2020 09:06 — forked from kevinmehall/replace_ecs_cluster_instances.py
Script to drain and replace EC2 instances in an ECS cluster auto-scaling group after changing the AMI or instance type
#!/usr/bin/env python3
#
# Script to replace EC2 instances in an ECS cluster's auto-scaling group after
# changing the AMI or instance type in the launch configuration. It
# checks for instances with the incorrect AMI or type, scales up the
# auto-scaling group with replacement instances, then drains the tasks
# from the old instances.
#
# Usage: aws-vault exec profile-name -- python3 replace_ecs_cluster_instances.py --group=asg-name --cluster=ecs-cluster-name --count=3
#
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:DescribeSessions",
"ssm:GetConnectionStatus",
"ssm:DescribeInstanceProperties",
"ec2:DescribeInstances",

How to use this script:

route53-zone-migrate.sh -s aws_source_profile -t aws_target_profile -d domain_name

Help

 -s,    Uses a AWS CLI profile name for Route53 zone source account.
 -t, Uses a AWS CLI profile name for Route53 zone target account.