Skip to content

Instantly share code, notes, and snippets.

View mikepfeiffer's full-sized avatar
🏠
Working from home

Mike Pfeiffer mikepfeiffer

🏠
Working from home
View GitHub Profile
@mikepfeiffer
mikepfeiffer / gist:4d9386afdcceaf29493a
Created March 19, 2016 22:54
EC2 UserData script to install CodeDeploy agent
#!/bin/bash
yum install -y aws-cli
cd /home/ec2-user/
aws s3 cp 's3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm' . --region us-east-1
yum -y install codedeploy-agent.noarch.rpm
@mikepfeiffer
mikepfeiffer / gist:a4ce6d25ae092f1a4ea97afad5879530
Last active July 24, 2020 08:44
EC2 user data script to boostrap Windows instance with Python and AWS CLI
<powershell>
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
choco install python -y
(new-object net.webclient).DownloadFile('https://s3.amazonaws.com/aws-cli/AWSCLI64.msi','c:\AWSCLI64.msi')
msiexec.exe /i 'C:\AWSCLI64.msi' /qn
</powershell>
@mikepfeiffer
mikepfeiffer / gist:d889b3bc78b68193e407d487b197be04
Created May 9, 2016 20:39
EC2 user data script to bootstrap instance with CloudWatch sample scripts
#!/bin/bash
yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https -y
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
unzip CloudWatchMonitoringScripts-1.2.1.zip
rm CloudWatchMonitoringScripts-1.2.1.zip
@mikepfeiffer
mikepfeiffer / gist:3851e3bd95591e0675aa4c76cd57635f
Created May 16, 2016 17:42
AWS Lambda Function to Start an EC2 Instance
var AWS = require('aws-sdk');
exports.handler = function(event, context) {
var ec2 = new AWS.EC2({region: 'us-east-1'});
ec2.startInstances({InstanceIds : ['i-0114833f8ffc9151c'] },function (err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
context.done(err,data);
});
};
@mikepfeiffer
mikepfeiffer / gist:7c949e2d04c9e51ef204fb9a7f3d2978
Last active January 21, 2024 20:37
Userdata script to setup a basic web page with instance id and tag instance
#!/bin/bash
yum install httpd -y
/sbin/chkconfig --levels 235 httpd on
service httpd start
instanceId=$(curl http://169.254.169.254/latest/meta-data/instance-id)
region=$(curl http://169.254.169.254/latest/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')
echo "<h1>$instanceId</h1>" > /var/www/html/index.html
aws ec2 create-tags --resources "$instanceId" --tags Key=Name,Value="PROD-$instanceId" --region "$region"
@mikepfeiffer
mikepfeiffer / gist:6f9e6cac7607fc365874cd7d31dbb141
Last active May 27, 2021 09:29
Example to Create AWS ELB, Launch Config, and Auto Scaling Group
aws elb create-load-balancer \
--load-balancer-name MyELB \
--listeners Protocol=TCP,LoadBalancerPort=80,InstanceProtocol=TCP,InstancePort=80 \
--subnets subnet-46e6506c subnet-57b8010f \
--scheme internet-facing \
--security-groups sg-aec570d4
aws autoscaling create-launch-configuration \
--launch-configuration-name MyLC \
--key-name virginia \
@mikepfeiffer
mikepfeiffer / gist:4aea8cba143ff31fa90a33ff4818b809
Created August 27, 2016 19:30
How to create and complete a lifecycle hook
aws autoscaling put-lifecycle-hook \
--lifecycle-hook-name scale-out-hook \
--auto-scaling-group-name MyASG \
--lifecycle-transition autoscaling:EC2_INSTANCE_LAUNCHING
aws autoscaling complete-lifecycle-action \
--lifecycle-action-result CONTINUE \
--instance-id i-0680775fb68bc97a5 \
--lifecycle-hook-name scale-out-hook \
--auto-scaling-group-name MyASG
@mikepfeiffer
mikepfeiffer / apache.sh
Last active June 20, 2021 15:35
Setup Apache on Amazon Linux
#!/bin/bash
yum update -y
yum install -y httpd24 php70 mysql php70-mysqlnd
service httpd start
chkconfig httpd on
usermod -a -G apache ec2-user
sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www
@mikepfeiffer
mikepfeiffer / wordpress.sh
Created April 10, 2018 18:45
Download and Deploy WordPress Application Code for Apache
#!/bin/bash
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
cp -r wordpress/* /var/www/html/
#!/bin/bash
yum update -y
yum install -y httpd24 php56 mysql php56-mysqlnd
service httpd start
chkconfig httpd on
echo "fs-56fc251e.efs.us-east-1.amazonaws.com:/ /var/www/html nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 0 0" >> /etc/fstab
mount -a