Skip to content

Instantly share code, notes, and snippets.

View amcginlay's full-sized avatar

Alan McGinlay amcginlay

View GitHub Profile
@amcginlay
amcginlay / simpleweb.sh
Last active July 17, 2019 15:43
AWS EC2 Simple Web Server
#!/bin/bash
yum update -y
yum install httpd -y
service httpd start
chkconfig httpd on
echo "<html><h1>This is Webserver X</h1></html>" > /var/www/html/index.html
@amcginlay
amcginlay / codedeploy.sh
Last active August 6, 2019 12:14
Install CodeDeploy agent on your EC2 instance
#Install CodeDeploy agent on your EC2 instance:
sudo yum update -y
sudo yum install ruby
sudo yum install wget
cd /home/ec2-user
wget https://aws-codedeploy-eu-central-1.s3.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
sudo service codedeploy-agent status
#Create your application.zip and load it into CodeDeploy:
@amcginlay
amcginlay / mysql.sh
Last active August 6, 2019 12:15
AWS EC2 MySQL
#!/bin/bash
yum update -y
yum install httpd php php-mysql -y
chkconfig httpd on
service httpd start
echo "<?php phpinfo();?>" > /var/www/html/index.php
cd /var/www/html
wget https://s3.amazonaws.com/acloudguru-production/connect.php
@amcginlay
amcginlay / amazon-linux-docker.sh
Created August 20, 2019 21:45
Install docker on an Amazon LInux EC2 instance
# as per https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html
sudo yum update -y
sudo amazon-linux-extras install docker
sudo service docker start
sudo usermod -a -G docker ec2-user
@amcginlay
amcginlay / kinesis-firehose-demo
Last active October 15, 2019 17:18
Kinesis Firehose demo
# assumes a kinesis firehose delivery system is in place (e.g. demo-firehose-stream)
# NodeJS Lambda function to append CRs as follows with a timeout > 1 min
# Configure this to deposit results in S3
console.log('Loading function');
exports.handler = async (event, context) => {
/* Process the list of records and transform them */
@amcginlay
amcginlay / amazon-linux-nodejs-server
Last active October 15, 2019 17:20
nodejs server user data - example request: curl localhost/?workload=1000
#!/bin/bash
#############
# 1. Copy this script into EC2 User Data
# 2. Enable Cloudwatch detailed monitoring
# Usage: "curl localhost:80/?workload=1000"
#############
yum update -y
curl --silent --location https://rpm.nodesource.com/setup_10.x | bash -
@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-data-stream-demo
Last active November 11, 2019 12:14
Kinesis data stream demo
# assumes a data stream named "demo-stream" with one shard exists
# inspect data stream and copy identity SHARD_ID variable (e.g. ShardId-????)
aws kinesis list-streams
STREAM_NAME=demo-stream
aws kinesis describe-stream --stream-name ${STREAM_NAME}
SHARD_ID=shardId-000000000000
# add four records