Showing posts with label user data. Show all posts
Showing posts with label user data. Show all posts

Monday, June 23, 2014

AWS EC2 user data

You can perform any bootstrapping action you would like using user data.  Here is an example of installing Apache, PHP, and MySQL.  Then Apache, PHP and MySQL are started.  Then a sample application is installed on Apache.

#!/bin/sh
yum -y install httpd php mysql php-mysql
chkconfig httpd on
/etc/init.d/httpd start
cd /tmp
wget http://us-east-1-aws-training.s3.amazonaws.com/self-paced-lab-4/examplefiles-as.zip
unzip examplefiles-as.zip
mv examplefiles-as/* /var/www/html

Tuesday, December 3, 2013

Boot strap : NAT Instance

This is the user data boot strap script which 'makes' your EC2 instance into a NAT instance:
#!/bin/sh
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/eth0/send_redirects
/sbin/iptables -t nat -A POSTROUTING -o eth0 -s 0.0.0.0/0 -j MASQUERADE
/sbin/iptables-save > /etc/sysconfig/iptables
mkdir -p /etc/sysctl.d/
cat <<EOF > /etc/sysctl.d/nat.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.eth0.send_redirects = 0
EOF

Boot strapping - automatically install and start Apache on EC2 launch

Here is a very common user data boot strapping script for installing Apache, PHP, and starting the Apache server:
#!/bin/sh
yum -y install httpd php
chkconfig httpd on
/etc/init.d/httpd start

Boot strap PHP and ELB examples

Here is strap script that can be used to install and start Apache along with PHP.  It will then download and unzip the AWS ELB examples.

yum -y install httpd php
chkconfig httpd on
/etc/init.d/httpd start
cd /var/www/html
wget http://bootstrapping-assets.s3.amazonaws.com/examplefiles-elb.zip

unzip examplefiles-elb.zip

Saturday, August 10, 2013

Boot strapping with user data and CloudFormation

For simple bootstrapping, user data text/scripts may be adequate.  Keep in mind the limit on size is 16K for user data.


s3cmd is often used to load the bootstrap scripts for S3. More on this can be found here:

A very good document on using user data, CloudFormation, Chef, Puppet and other tools to bootstrap EC2 instances can be found here:

Tuesday, April 16, 2013

User data to install Apache and PHP


One of the most basic components on an EC2 instance is Apache and PHP.  Installing Apache and PHP is made easy with a short shell script, yum, and user data.  Here is all that needs to be placed in the user data section of the EC2 instance:

#!/bin/sh
yum -y install httpd php
chkconfig httpd on
/etc/init.d/httpd start