Project: Backstage (App Definition and Development / Application Definition & Image Build)
File: aws-deployment.md

Backstage documentation shows how to build a ; this tutorial shows how to deploy that Docker image to AWS using Elastic Container Registry (ECR) and Elastic Kubernetes Service (EKS). Amazon also supports deployments with Helm, covered in the example. The basic workflow for this method is to build a Backstage Docker image, upload the new version to a container registry, and update a Kubernetes deployment with the new image. To create an Elastic Container Registry on AWS, go to the . Click `Create repository` and give the repository a name, like `backstage`. To push to this new ECR repository, there must be an IAM user with `AmazonEC2ContainerRegistry` permission. Go to and select `Users`. Click `Add User` Set the username to something like `ecr-publisher` and select `Programmatic access` only. For `Permissions`, you can either create a new group or attach policies directly to the user with `AmazonEC2ContainerRegistryFullAccess`. Finish creating the user; an access key ID and secret access key will be generated. Follow the documentation to build a new Backstage Docker image: ```shell $ yarn build:backend $ yarn build-image --tag backstage ``` Next, configure the to use the `ecr-publisher` user you created: ```shell $ aws configure AWS Access Key ID: <access key ID> AWS Secret Access Key: <secret access key> Default region name: <region for your ECR repository> ``` Now you can use the AWS CLI to push the built image to the ECR repository. It's a good practice to use a specific version tag as well as `latest` when pushing; more about . Go to the and click on your repository, then `View push commands`. This will show the repository URL to push and some sample commands. ```shell $ aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <repo_url> Login Succeeded $ docker tag backstage:latest <repo_url>/backstage:latest $ docker push <repo_url>/backstage:latest $ docker tag backstage:latest <repo_url>/backstage:1.0.0 $ docker push <repo_url>/backstage:1.0.0 ``` These will take a few minutes to upload the Docker images, then you can see the image with `latest, 1.0.0` tags in the ECR repository. Now you can create a Kubernetes deployment based on this image. Creating an Elastic Kubernetes Service (EKS) cluster is beyond the scope of this document, but it can be as easy as `eksctl create cluster` documented in the , which uses a Cloudformation template to create the necessary resources. To deploy the Docker image to EKS, follow the but set the Backstage deployment `image` to the ECR repository URL: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: backstage namespace: backstage spec: ... template: metadata: labels: app: backstage spec: containers: image: <repo_url>/backstage:1.0.0 imagePullPolicy: Always ... ``` Create the as well, and apply these Kubernetes definitions to the EKS cluster to complete the Backstage deployment: ```shell $ kubectl apply -f kubernetes/backstage.yaml $ kubectl apply -f kubernetes/backstage-service.yaml ``` Now you can see your Backstage workload running from the . To make the service useful, we need to expose the workload with a load balancer. Follow the guide to set up a Load Balancer controller and Kubernetes ingress to your application. This is ultimately a `kubectl apply` with an ingress definition: ```yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: namespace: default name: backstage-ingress annotations: kubernetes.io/ingress.class: alb alb.ingress.kubernetes.io/scheme: internet-facing alb.ingress.kubernetes.io/target-type: ip spec: rules: http: paths: path: / pathType: Prefix backend: service: name: backstage-backend port: number: 80 ```