This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-manual-agent-install.html | |
sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm | |
# this to check | |
sudo systemctl status amazon-ssm-agent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inspired by https://jameshfisher.com/2018/12/31/how-to-make-a-webserver-with-netcat-nc/ | |
#!/bin/bash | |
yum install -y socat | |
socat TCP4-LISTEN:${PORT:-80},fork SYSTEM:' \ | |
read -r line \ | |
read -r _ workload _ <<< "$line" \ | |
workload=${workload:1} | |
[ ! -z "$workload" ] && timeout $workload yes > /dev/null \ | |
echo HTTP/1.0 200 \ | |
echo Content-Type\: text/plain \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
yum install -y socat | |
socat TCP4-LISTEN:80,fork SYSTEM:' \ | |
echo HTTP/1.0 200 \ | |
echo \ | |
echo Response from $(hostname) at $(date '+%s.%N')' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
yum update -y | |
yum install -y nfs-utils | |
FILE_SYSTEM_ID=fs-xxxxxxxx | |
AVAILABILITY_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone ) | |
REGION=${AVAILABILITY_ZONE:0:-1} | |
MOUNT_POINT=/mnt/efs | |
mkdir -p ${MOUNT_POINT} | |
chown ec2-user:ec2-user ${MOUNT_POINT} | |
echo ${FILE_SYSTEM_ID}.efs.${REGION}.amazonaws.com:/ ${MOUNT_POINT} nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,_netdev 0 0 >> /etc/fstab |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo yum update -y | |
sudo yum install -y ruby wget | |
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install | |
chmod +x ./install | |
sudo ./install auto | |
sudo service codedeploy-agent status |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for region in $(aws ec2 describe-regions --query "Regions[*].[RegionName]" --output text); do | |
echo "--- ${region} ---" | |
aws ec2 describe-vpcs --region ${region} --query "Vpcs[].[VpcId,Tags[?Key=='Name'].Value | [0]]" --output text | while read vpcdata; do | |
set $vpcdata; vpcid=${1}; vpcname=${2} | |
aws ec2 describe-security-groups --region ${region} --filters "Name=vpc-id,Values=${vpcid}" --query "SecurityGroups[].[GroupId,GroupName]" --output text | while read sgdata; do | |
set $sgdata; sgid=${1}; sgname=${2} | |
if [ "${sgname}" != "default" ]; then | |
usagecount=$(aws ec2 describe-network-interfaces --region ${region} --filters "Name=group-id,Values=${sgid}" --query "NetworkInterfaces[] | length(@)" --output text) | |
if [ "${usagecount}" == "0" ]; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
aws iam list-policies --scope Local --query "Policies[?AttachmentCount == \`0\`].[PolicyName]" --output text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
aws iam get-account-authorization-details --query "RoleDetailList[].[RoleLastUsed.LastUsedDate, RoleName]" --output text | sed -e 's/^None/1970-01-01T00:00:00+00:00/g' | sort | while read roledata; do | |
set $roledata; rolelastused=${1:0:10}; rolename=${2} | |
daysago=$((($(date +%s)-$(date -j -f "%Y-%m-%d" ${rolelastused} +%s))/86400)) | |
echo "${rolename} (used ${daysago} days ago)" | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mkdir myubuntu && cd $_ | |
echo "FROM ubuntu:latest" > Dockerfile | |
docker build -t myubuntu . # notice IMAGE ID will be identical to ubuntu:latest as no extra layers added | |
docker container run -it myubuntu /bin/bash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -L https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz -o etcd-v3.4.13-linux-amd64.tar.gz | |
tar xavf etcd-v3.4.13-linux-amd64.tar.gz | |
cd etcd-v3.4.13-linux-amd64 | |
./etcd | |
./etcdctl # to view help | |
./etcdctl put key1 value1 | |
./etcdctl get key1 |