Skip to content

Instantly share code, notes, and snippets.

View amcginlay's full-sized avatar

Alan McGinlay amcginlay

View GitHub Profile
@amcginlay
amcginlay / kinesis-dump-all
Last active November 12, 2019 21:39
AWS CLI command to dump the contents of a Kinesis stream shard
STREAM_NAME=wildrydes
SHARD_ID=ShardId-000000000000
aws kinesis get-records --shard-iterator $( \
aws kinesis get-shard-iterator \
--stream-name ${STREAM_NAME} \
--shard-id ${SHARD_ID} \
--shard-iterator-type TRIM_HORIZON \
--output text \
) --output text --query 'Records[*].[Data]' | while read line ; do echo $line | base64 --decode ; echo ; done
@amcginlay
amcginlay / ubuntu-linux-docker.sh
Last active November 27, 2019 19:23
Install docker on an Ubuntu instance
# Ubuntu ONLY! Amazon Linux instructions here:
# (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html#install_docker)
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
sudo usermod -a -G docker ubuntu
sudo reboot
@amcginlay
amcginlay / list-own-tags.sh
Created December 2, 2019 17:02
command for listing all the tags in current EC2 instance
aws ec2 describe-tags \
--filters "Name=resource-id,Values=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)"
@amcginlay
amcginlay / daily-max-cpu.sh
Last active December 20, 2019 14:41
Cloudwatch Daily Maximum CPU Utilization
aws cloudwatch get-metric-statistics \
--namespace AWS/EC2 \
--metric-name CPUUtilization \
--statistics Maximum \
--start-time 2019-01-01T00:00:00Z \
--end-time 2020-01-01T00:00:00Z \
--period $((60*60*24)) \
--query 'sort_by(Datapoints,&Timestamp)[*]'
@amcginlay
amcginlay / cf-mvp.yaml
Last active April 14, 2020 15:30
CloudFormation Template MVP
# https://adamj.eu/tech/2019/08/19/cloudformation-minimum-viable-template/
AWSTemplateFormatVersion: 2010-09-09
Resources:
Topic:
Type: AWS::SNS::Topic
@amcginlay
amcginlay / linux_amd64-amazon-ssm.sh
Last active April 24, 2020 16:20
Manually install SSM Agent on EC2 instances for Linux
#!/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
@amcginlay
amcginlay / amazon-linux-socat-server.sh
Last active June 3, 2020 11:37
socat server user data - example request: curl localhost/3
# 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 \
#!/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')'
#!/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
function Button() {
const [counter, setCounter] = useState(0);
return <button onClick={() => setCounter(counter+1)}>{counter}</button>;
}
ReactDOM.render(
<Button />,
document.getElementById('mountNode'),
);