I have created an EC2 instance using auto-scaling. After the first instance is created, I go to that EC2 instance via puTTy. Then I cloned my repository, and move those files to the required directory (/var/www/html).
I am wondering that if the second istance is created, would it contain the same configuration automatically as I did in the first Ec2 instance? Or it won't create the same configuration? Do I have to handle the manual steps in the User Data of auto scaling configuration?
The steps I perform manually on the machine are following:
- clone the repository using
git clone https://github.com/rais24/simple-html-landing-page.git
- Move the subfolder files (README.md, assets, index.html) to the apache server directory that is /var/www/html
I used mv command like this
mv index.html /var/www/html
same command for assets and README.md files.
How I can convert these steps to bash script that is used in auto scaling? I don't have any idea if it creates all other EC2 instance with same configuration or it only create new machine empty?
CodePudding user response:
The instance spawned depends on th launch configuration autoscaling uses.
To execute the script on ec2 creation you will have to modify the launch configuratiin that autoscaling is using to launch instances
The script should be something along thse lines. (These should be the steps you already tried out manually)
#!/bin/bash
yum update -y
yum install git
git clone https://github.com/rais24/simple-html-landing-page.git
mv simple-html-landing-page/README.md
var/www/html
https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_CreateLaunchConfiguration.html
UserData: The user data to make available to the launched EC2 instances
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html#user-data-shell-scripts