How to use bootstrap script in AWS ( EC2 Instance )

This tutorial will explain about how to use bootstrap script in AWS


What is Bootstrap Script(Bootstrapping) in AWS ?


Bootstrapping allows us to write and put a startup script while launching an EC2 Instance so that it execute automatically as soon as the instance launch.

Let’s suppose you have to launch an ec2 instances with Apache HTTPD installed on the System.So instead of installing HTTPD  the server  manually , you can launch EC2 Instances using Bootstrap Script.


How to Use Bootstrap Script  in AWS?


Step 1 – Login to your AWS Account and Launch an Instance


If you don’t have AWS account , you can create a free tier account by following link.

Create AWS Free Tier Account


Now launch an EC2 Linux Instance with Amazon Linux 2 as an O/S .Follow my previous article  How to launch Linux Virtual Machine on AWS  to launch an EC2 Linux Instance but make sure to use the following script in User Data  as mentioned below:


Under Configure Instance  in Advance Details put the following Example Bash Script. You can put any other script  as per your requirement and use case.


#! /bin/bash

sudo yum update -y

sudo yum install httpd -y

sudo service httpd start && sudo chkconfig httpd on



Connect EC2 Linux Instance


Step 2 – Connect to ec2 instance using ssh

Connect your AWS EC2 Linux Instance using SSH


 $ sudo ssh -i your_private_key.pem [email protected]_instance_public_ip_address




Verify the Bootstrap Script


Step 3 – Verify if script ran properly


$ sudo yum history

Here you can see in the screenshot , all the commands in bootstrap script ran properly.



you can also check the httpd service status using following command.


 $ sudo service httpd status



Similarly, you can also use a bootstrap script for AWS Windows Instance as well using Batch/Power shell script.

If you want to learn how to launch EC2 Windows Instance read my previous article How to Launch Windows Virtual Machine in AWS


Click to tweet this tip !


Thanks for reading this tutorial about How to use bootstrap script in AWS ( EC2 Instance ). If you think this article is really helpful, please do support us to share this article with others directly or via Social media.

Please also share your valuable feedback, comment, or any query in the comment box.I will really happy to resolve your queries.

Thank You

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter

You may also like…

Leave a Reply

Your email address will not be published. Required fields are marked *