how to set automatic git pull from bitbucket and complie project on ec2 instance create event with auto scaling I have just started reading about AWS services. I have a project where the backend is created with Spring-Boot, front-end is created with React and PostgreSQL is used as database. Both backend and frontend is different bitbucket repository. I want to use two different EC2 instance for front &amp; back-end and RDS for PostgreSQL. Now I also want to use the autoscaling feature. The problem is how can I set the autoscaling feature in such a fashion where it automatically clone the app from bitbucket and then run a shell script file to compile and run the application.
You want to make use of user_data scripts.
It's basically a bootstrap shell script that gets executed on an instance during launch.
You can embed your app configuration script in there (either directly via bash, or have it call your configuration management software like Ansible or Chef).
Then, if you attach this script to a Launch Template or a Launch Configuration (which is an instance template required as part of an AWS ASG), it will be applied to the whole autoscaling group.
Then, when you have a scaling event, any new instances that come up in the ASG will run the script and deploy your code.
However, I would recommend you look into immutable infrastructure instead.  I.e. set up automation (i.e. via Packer) that builds your application code into your AMI, with user_data only used for actually starting the app.
Then, when you have a new build, have the same automation build a new AMI and replace your ASG (note you'll need to have your ASG created/deployed in a programmatic fashion.. I personally recommend Terraform).