Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Arbab Nazar arbabnazar

🏠
Working from home
View GitHub Profile
@arbabnazar
arbabnazar / replace_ecs_cluster_instances.py
Created Dec 3, 2020 — 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
View replace_ecs_cluster_instances.py
#!/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
#
View SSMAccess.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssm:DescribeSessions",
"ssm:GetConnectionStatus",
"ssm:DescribeInstanceProperties",
"ec2:DescribeInstances",
View README.md

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.
View git-empty-branch.md
$ git checkout --orphan NEWBRANCH
$ git rm -rf .

--orphan creates a new branch, but it starts without any commit. After running the above command you are on a new branch "NEWBRANCH", and the first commit you create from this state will start a new history without any ancestry.

You can then start adding files and commit them and they will live in their own branch. If you take a look at the log, you will see that it is isolated from the original log.

@arbabnazar
arbabnazar / Java 8 PPA
Last active Jan 5, 2020
Java 8 working till today
View Java 8 PPA
sudo add-apt-repository ppa:ts.sch.gr/ppa
sudo apt-get update
sudo apt-get install oracle-java8-installer
@arbabnazar
arbabnazar / Build an AWS Lambda deployment package for Python.md
Last active Jan 4, 2020
Build an AWS Lambda deployment package for Python
View Build an AWS Lambda deployment package for Python.md

Install all dependency modules local to the function project

pip install boto3 -t ./

Add permissions (Linux and macOS only)

chmod -R 755 .

Manually build a deployment package

@arbabnazar
arbabnazar / Change Hostname in Ubuntu 16.04 Without Restart
Created Dec 31, 2019
Change Hostname in Ubuntu 16.04 Without Restart
View Change Hostname in Ubuntu 16.04 Without Restart
vi /etc/hosts
vi /etc/hostname
hostnamectl set-hostname stage-vpn-server
hostname
--------
OPTIONAL
--------
service hostname start
systemctl restart systemd-logind.service
View Resize AWS EBS without Rebooting
let’s list block devices attached to our box:
lsblk
# install "cloud-guest-utils" if it is not installed already
apt install cloud-guest-utils
# resize partition
growpart /dev/xvda 1
# resize filesystem
@arbabnazar
arbabnazar / ubuntu-hardening.md
Created Oct 10, 2019 — forked from lokhman/ubuntu-hardening.md
List of things for hardening Ubuntu
View ubuntu-hardening.md

System Updates

http://bookofzeus.com/harden-ubuntu/initial-setup/system-updates/

Keeping the system updated is vital before starting anything on your system. This will prevent people to use known vulnerabilities to enter in your system.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get autoremove
sudo apt-get autoclean
@arbabnazar
arbabnazar / README
Created Oct 10, 2019
[Python] MFA authentication when using AWS CLI
View README
**Try to run**
```
python export_commands_generation.py
Enter your token code: 123456
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
export AWS_SESSION_TOKEN=FQoGZXIvYXdzIn
```
**Try exporting to an environment variable**
Copy, paste, and execute the 3-line export command output by the script.
You can’t perform that action at this time.