Skip to content

Instantly share code, notes, and snippets.

View amcginlay's full-sized avatar

Alan McGinlay amcginlay

View GitHub Profile
@amcginlay
amcginlay / base64-zip.sh
Last active October 30, 2019 17:14
Serialization and compression demo
echo "Alan" | base64 | base64 --decode
convert -size 2560x1600 canvas:red ~/tx.png # reaquires imagemagick
find . -maxdepth 1 -type f -name '*x.png*' -exec ls -l {} \;
base64 ~/tx.png > ~/tx.png.b64
zip ~/tx.png.b64.zip ~/tx.png.b64
cp ~/tx.png.b64.zip ~/rx.png.b64.zip
# execute the following command from the terminal of a new c9 workspace
git clone https://github.com/amcginlay/nodejs-chat.git
cd nodejs-chat
npm install
# Now ...
# - open server.js and click the green run button
# - click Preview / Preview Running Application
# - in the mini-browser window, click the stacked window icon to open in a new tab
@amcginlay
amcginlay / aws-vpn.sh
Last active November 9, 2019 20:05
How to build a VPN in AWS
- Create VPC-A in us-west-2 on 10.100.0.0/16 with IGW and public subnet on 10.100.0.0/24
- Create VPC-B in us-east-2 on 10.200.0.0/16 with IGW and public subnet on 10.200.0.0/24
- Create EC2-A in 10.100.0.0/24 with all TCP & ICMP ports open to 10.200.0.0/24
- Create EC2-B in 10.200.0.0/24 with all TCP & ICMP ports open to 10.100.0.0/24
- Allocate EC2-B an Elastic IP address
- Create a Virtual Private Gateway (VGW) attached to VPC-A
- Create a Customer Gateway (CGW) referencing EC2-B's Elastic IP address
- Create a VPN Connection (VPN), referencing the VGW, the CGW and static route 10.200.0.0/24
- Download the Generic VPN configuration file
@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 / assume-iam-role.sh
Created November 27, 2019 00:27
How do I assume an IAM role using the AWS CLI?
How to assume an IAM role using the AWS CLI
===========================================
# from admin session
# TODO fix this to eliminate ACCOUNT_ID env var
ACCOUNT_ID=$(aws sts get-caller-identity --query "Account" --output text)
aws iam create-user --user-name test-user
cat << EOF > test-policy.json
{
"Version": "2012-10-17",
"Statement": {
@amcginlay
amcginlay / list-all-arns.sh
Last active July 26, 2023 10:45
command for listing all ARNs in current account
for region in $(aws ec2 describe-regions --query 'Regions[*].[RegionName]' --output text); do
# echo "--- ${region} ---"
aws resourcegroupstaggingapi get-resources \
--region ${region} \
# --resource-type-filters 'ec2:instance' \
--query 'ResourceTagMappingList[*].[ResourceARN]' \
--output text;
done
@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)[*]'
function Button() {
const [counter, setCounter] = useState(0);
return <button onClick={() => setCounter(counter+1)}>{counter}</button>;
}
ReactDOM.render(
<Button />,
document.getElementById('mountNode'),
);
@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