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 & 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.

  • 1
    This could be done with a cloud init user data section or with a systemd unit... as well as a cron job and many other ways. We would need more context on how you are deploying these instances. What process are you using to make the AMIs, what does the pipeline look like, what tools are you using? Jan 25, 2021 at 10:51

1 Answer 1


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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.