Skip to content

Instantly share code, notes, and snippets.

@serkanh
serkanh / gist:3d61feded47b975da5f061c90591d0b9
Created February 27, 2018 17:08
sort ecr images by push date and get the latest
aws --profile=jumpstart ecr describe-images --repository-name lead-front-door \
--query 'sort_by(imageDetails,& imagePushedAt)[-1].imageTags[0]' --output text
@serkanh
serkanh / csvimporter.py
Created September 16, 2012 15:08
Simple CSV importer
from django.core.management import setup_environ
import settings, csv
setup_environ(settings)
from companies.models import Lead
file = csv.reader(open('florida.csv', 'rU'), delimiter = ',', quotechar='|')
for row in file:
#Name the Django field with corresponding row in your csv.
lead = Lead(cname=row[0], crep=row[1], cnumber=row[2], cemail=row[3], caddress=row[4], ccity=row[5],czip=row[6],submissiondate=row[7], businesstype = row[8], comment = row[9])
lead.save()
#/usr/local/bin/bash
#set -x
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
declare -a folders
@serkanh
serkanh / UserData script for setup CloudWatch
Last active September 21, 2020 12:46 — forked from martinzuern/UserData script for setup CloudWatch
With this user data script, you can set up cron job to put some custom metrics for CloudWatch at instance initiation.
#!/bin/sh
yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA unzip
cd /home/ec2-user
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
unzip CloudWatchMonitoringScripts-1.2.1.zip
rm -rf CloudWatchMonitoringScripts-1.2.1.zip
chown ec2-user:ec2-user aws-scripts-mon
echo "* * * * * /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --swap-util --aggregated --auto-scaling --from-cron" >> /var/spool/cron/ec2-user
echo "0 * * * * /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --disk-space-used --disk-space-avail --disk-space-util --disk-path=/ --aggregated --auto-scaling --from-cron" >> /var/spool/cron/ec2-user
@serkanh
serkanh / gist:c75a323218cc220f8ea188066838faaa
Last active August 7, 2019 03:49
aws user-data script to monitor memory & volume utilization of ec2 instances
#/bin/bash
sudo yum install unzip wget perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA -y
wget -O ~ec2-user/CloudWatchMonitoringScripts-1.2.1.zip http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip
cd ~ec2-user && unzip CloudWatchMonitoringScripts-1.2.1.zip
chown ec2-user:ec2-user ~ec2-user/aws-scripts-mon
rm CloudWatchMonitoringScripts-1.2.1.zip
crontab -l > ~ec2-user/mycron
echo "*/5 * * * * ~ec2-user/aws-scripts-mon/mon-put-instance-data.pl --disk-space-util --disk-path=/ --from-cron" >> ~ec2-user/mycron
echo "*/5 * * * * ~ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-used --mem-avail --swap-used" >> ~ec2-user/mycron
crontab ~ec2-user/mycron
#!/bin/bash
if [ $# -lt 3 ]; then
echo "To update fastly dynamic vcls"
echo "----------------------------"
echo "https://docs.fastly.com/vcl/vcl-snippets/using-dynamic-vcl-snippets/"
echo "$0 <fastly-key> <service-number> <revision-number>"
exit 1
@serkanh
serkanh / gist:382bbf454a123214d02681294a1348ad
Last active February 27, 2019 13:49
search user owned repos excluding forks.
curl https://api.github.com/users/serkanh/repos\?per_page\=1000 | jq '.[] | select(.fork==false) | .html_url'
curl https://api.github.com/users/serkanh/repos\?per_page\=1000 | jq '.[] | select(.fork==false and .language=="JavaScript") | .html_url'
@serkanh
serkanh / gist:64c91898187e2ab03ae9cdc5e1d81114
Last active October 13, 2018 23:20
to get decoded user data from ec2 instances
#/bin/bash
trap exit INT
INSTANCES=$( aws --profile=HA ec2 describe-instances --query 'Reservations[].Instances[].InstanceId[]' | sed -e 's/\[//g' -e 's/\]//g')
SUM=0
echo $INSTANCES
for i in $( echo $INSTANCES | sed -e 's/"//g' -e 's/,//g' -e 's/\[//g' -e 's/\]//g' ) ;do
echo "---------------------------$i-------------------------------\n"
aws --profile=HA ec2 describe-instances --instance-ids $i --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value' --output text
aws --profile=HA ec2 describe-instance-attribute --instance-id $( echo $i | sed -e 's/"//g' -e 's/,//' -e 's/\[//g' -e 's/\]//g' ) --attribute userData \
| jq '.UserData.Value' | sed 's/"//g' | base64 --decode
#!/bin/sh
#set -ox
#either pass slack token as a param or env var SLACK_TOKEN=${1:SLACK_TOKEN}
SLACK_TOKEN=${SLACK_TOKEN}
# Get the list of channels
# https://api.slack.com/methods/channels.list/test
aws --profile=HA sns list-subscriptions \
--query 'Subscriptions[*]|[?contains(Protocol,`lambda`)==`false`]|[?contains(Endpoint,`bark`)==`true`]|[?contains(Endpoint,`stg`)==`true`]|[?contains(TopicArn,`d6cbe`)==`false`].{TopicArn:TopicArn}' --output text