4.16 Using Bootstrap Scripts
Bash Script Lab
Create an index.html
Switch your Region to North Virginia.
Create a new S3 bucket and upload your index.html to it. Remember your object is private in default, you cannot visit it through the IP of the S3 bucket, but you can copy it to a EC2 instance so that visit it through EC2 instance's web server.
Create a new EC2 Role which gives you AmazonS3FullAccess.
Create a new EC2 instance. In the Configure Instance Details step, attach the Role you just created to be the IAM Role of this instance. At the Advanced Details, in the User data text area, you need to type "#!/bin/bash", at a new line, type "yum update -y", so the interpreter will interpret the bash commands and run them sequentially at root level when this instance first start up.
SSH to your instance, and go head to be the root user.
Download and start an Apache httpd server and copy index.html from S3 bucket to this instance. Using commands "yum install httpd -y", "service httpd start", "chkconfig httpd on", "cd /var/www/html", "aws s3 cp s3://[your-s3-bucket-name]/index.html /var/www/html". Because you are now in North Virginia Region, so you will probably not need to append a Region argument, like "--region [your-current-region-name]".
All the bold commands above can be written into a .sh file, or you can just directly write them into text area of "Advanced Details" when you configure your new EC2 instance so that these commands can be run automatically when you every time boot up your instance.
Last updated
Was this helpful?