d
WE ARE EXPERTS IN TECHNOLOGY

Let’s Work Together

n

StatusNeo

Launch Backstage on AWS EC2: The Ultimate Guide

Backstage, the open-source developer experience platform by Spotify, has been making waves in the tech community. However, one area where the documentation falls short is in providing a detailed guide for deploying Backstage on a virtual machine. If you’re looking to deploy Backstage on an AWS EC2 instance, this guide will take you through the process step by step.

backstage on ec2 aws

Step 1: Launching Your EC2 Instance

Choose Your Instance Type

Start by launching an EC2 instance. For optimal performance, select a T2Large instance or above.

Configure Security Groups

To ensure your instance is accessible, configure the security group to allow traffic on ports 3000 and 7000. These ports will be used by the Backstage frontend and backend respectively.

Update and Upgrade Packages

Once your instance is up and running, SSH into your EC2 instance and run the following commands to update and upgrade your packages:

$ sudo apt-get -y update
$ sudo apt-get -y upgrade

Step 2: Install Required Software

Node.js and Yarn

Install Node.js using NVM and then install Yarn globally:

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
$ nvm install 20
$ npm i -g yarn

Python and Additional Tools

Install Python and other necessary tools for Backstage:

$ sudo apt install -y python3-pip
$ pip3 install cookiecutter --break-system-packages # Scaffolder
$ pip3 install mkdocs --break-system-packages # MkDocs
$ pip3 install mkdocs-techdocs-core --break-system-packages # TechDocs

Nginx

Install Nginx to manage web traffic:

$ sudo apt install -y nginx

Step 3: Configure Nginx

Create a new Nginx configuration file:

$ sudo vi /etc/nginx/sites-enabled/<domain>.com

Add the following configuration to route traffic correctly:

server {
    listen 80;
    server_name subdomain.rearportal.com;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:3000;
        proxy_redirect off;
    }

    location /api/ {
        proxy_pass http://127.0.0.1:7000;
    }
}

Save and close the file. Restart Nginx to apply the changes:

$ sudo systemctl restart nginx

Step 4: Clone the Backstage Repository

Clone your Backstage repository and update the app-config.yaml file:

$ cd /path/to/your/backstage-app
$ yarn install

# Update app-config.yaml
# Replace <EC2-internal-ip> and <subdomain.domain.com> with your values
$ vi app-config.yaml

Update the frontend and backend URLs in the configuration file:

frontend:
  baseUrl: http://<EC2-internal-ip>:3000
backend:
  baseUrl: https://subdomain.domain.com

Step 5: Setup Application Load Balancer (ALB) and Route 53

Create a Target Group

Create a target group in AWS that maps to HTTP port 80.

Create an ALB

Create an Application Load Balancer that routes HTTP traffic to HTTPS, linking the HTTPS listener to the previously created target group. Attach an SSL certificate from ACM or your preferred source to the HTTPS listener.

Configure Route 53

In your domain’s hosted zone, create a new A record for subdomain.domain.com that points to the ALB.

Step 6: Initialize Backstage

Start the Backstage application on your EC2 instance:

$ cd /path/to/your/backstage-app
$ yarn install

# If using Node 20 or above, run:
$ export NODE_OPTIONS=--no-node-snapshot

$ nohup yarn dev &

Conclusion

Congratulations! You now have a fully operational Backstage instance running on an AWS EC2 instance. This setup not only leverages the scalability of AWS but also ensures that your Backstage application is secure and accessible. Happy developing!

By following these steps, you’ll have a robust and efficient environment for all your developer experience needs. Enjoy the power and flexibility that Backstage on AWS EC2 offers!

Special thanks to @Aayush Saini and @Aviral Dwivedi for their contributions.