Skip to content

Instantly share code, notes, and snippets.

View eugenestarchenko's full-sized avatar
:octocat:

Eugene S eugenestarchenko

:octocat:
View GitHub Profile
@eugenestarchenko
eugenestarchenko / gist:de22b7c71d8b31cdaad2494f601bcf94
Created October 31, 2017 11:14 — forked from sebsto/gist:468670c7c0d5feeade69
AWS CLI : discover your service limits from the command line
aws support describe-trusted-advisor-check-result --check-id eW7HH0l7J9 --query 'result.sort_by(flaggedResources[?status!="ok"],&metadata[2])[].metadata' --output table --region us-east-1
@eugenestarchenko
eugenestarchenko / efs-backup.sh
Created December 11, 2017 12:04 — forked from xntric78/efs-backup.sh
Bash script to rsync files from one EFS to a backup EFS
#!/bin/bash
# Example would be to run this script as follows:
# Every 6 hours; retain last 4 backups
# efs-backup.sh $src $dst hourly 4 efs-12345
# Once a day; retain last 31 days
# efs-backup.sh $src $dst daily 31 efs-12345
# Once a week; retain 4 weeks of backup
# efs-backup.sh $src $dst weekly 7 efs-12345
# Once a month; retain 3 months of backups
# efs-backup.sh $src $dst monthly 3 efs-12345
@eugenestarchenko
eugenestarchenko / LambdaEfsBackup.py
Created December 21, 2017 11:09 — forked from eduardcloud/LambdaEfsBackup.py
Backup EFS file-system to S3 with lambda function
import boto3
import time
region = 'eu-west-1'
user_data_script = """#!/bin/bash
instanceid=$(curl http://169.254.169.254/latest/meta-data/instance-id)
cd /
mkdir moodledata
mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-xxxxxxxxxxc.efs.eu-west-1.amazonaws.com:/ moodledata
tar czf mooodledata-backup-$(date +%d-%m-%Y_%H-%M).tar.gz /moodledata
aws s3 mv mooodledata-backup-*.tar.gz s3://xxxxxxxxx/
@eugenestarchenko
eugenestarchenko / ecs-run
Created January 15, 2018 14:18 — forked from vcastellm/ecs-run
Run task and wait for result in AWS ECS
#!/usr/bin/env bash
set -e
function usage() {
set -e
cat <<EOM
##### ecs-run #####
Simple script for running tasks on Amazon Elastic Container Service
One of the following is required:
Required arguments:
@eugenestarchenko
eugenestarchenko / package-aws-lambda.sh
Created January 24, 2018 20:50 — forked from dionjwa/package-aws-lambda.sh
Given a source folder for an AWS Lambda package, builds and zips the lambda inside an AWS Linux docker container, ensuring all native node.js modules are compiled for the correct architecture.
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
echo ""
echo " Package an AWS Lambda script with all node modules into a zip file"
echo " The packager runs in an AWS Linux docker container, so the node "
echo " modules are compiled for the correct architecture."
echo ""
echo " -s/--src The source folder of the lambda script"
echo " -d/--destination The destination folder for the lambda zip file"
@eugenestarchenko
eugenestarchenko / ansible_conditionals_examples.yaml
Created February 14, 2018 13:58 — forked from marcusphi/ansible_conditionals_examples.yaml
Ansible 1.3 Conditional Execution -- Very complete example with comments -- I find the conditional expressions to be ridiculously hard to get right in Ansible. I don't have a good model of what's going on under the surface so I often get it wrong. What makes it even harder is that there has been at least three different variants over the course …
---
# This has been tested with ansible 1.3 with these commands:
# ansible-playbook -i hosts ansible_conditionals_examples.yaml --extra-vars="hosts=myhosts isFirstRun=false"
# ansible-playbook -i hosts ansible_conditionals_examples.yaml --extra-vars="hosts=myhosts isFirstRun=true"
# ansible-playbook -i hosts ansible_conditionals_examples.yaml --extra-vars="hosts=myhosts"
# NB: The type of the variable is crucial!
- name: Ansible Conditionals Examples
hosts: $hosts
vars_files:
@eugenestarchenko
eugenestarchenko / change-timezone.sh
Created February 19, 2018 12:17
Change Timezone on Linux
#!/bin/bash
ZONEFILEDIR="/usr/share/zoneinfo"
ZONEFOLDERNAME=$(echo $ZONEFILEDIR | awk 'BEGIN { FS="/" } { print $NF }')
usage() {
echo "usage: change-timezone.sh <-l [SEARCH] | -s ZONE>"
echo " -l -> List available timezones and search for SEARCH"
echo " -s -> Set timezone to ZONE (requires sudo/root access)"
}
@eugenestarchenko
eugenestarchenko / timezone.sh
Created February 19, 2018 12:19 — forked from gjpalau/timezone.sh
Script for managing timezones
#!/bin/bash
#### Set NTP Server
# Sets correct Timezone. If no Timezone is set, then default is CST
timezone=$1
if [ "$timezone" = "CST" ]
then
echo "America/Chicago"
@eugenestarchenko
eugenestarchenko / terminate_all_ec2.sh
Created March 11, 2018 18:28 — forked from rjurney/terminate_all_ec2.sh
Bash script to disable termination protection and then terminate all instances in all regions :)
for region in `aws ec2 describe-regions --output text | cut -f3`
do
echo "Terminating region $region..."
aws ec2 describe-instances --region $region | \
jq -r .Reservations[].Instances[].InstanceId | \
xargs -L 1 -I {} aws ec2 modify-instance-attribute \
--region $region \
--no-disable-api-termination \
--instance-id {}
aws ec2 describe-instances --region $region | \
@eugenestarchenko
eugenestarchenko / gist:2f4c43a0936d5fcc71faed952b0c2bad
Created March 15, 2018 15:07 — forked from oli-logicnow/gist:da1be4c9dccadb94670338e21bf4f348
Find all the keys and their associated user for a specific account
export PROFILE=XXXX
for USER in `aws --profile $PROFILE iam list-users --query 'Users[].UserName' --output text`
do
for KEY in `aws --profile $PROFILE iam list-access-keys --user-name "$USER" --query 'AccessKeyMetadata[].AccessKeyId' --output text`
do
echo $USER $KEY
done
done