top of page

Deploying to AWS with Fargate, Vapor, and Aurora Serverless Postgres RDS

The Swift Server Group recently posted a list of deployment guidelines for different instances, services, and cloud providers. Use the following breadcrumbs I'm presenting to deploy a Vapor application.


I chose to stick with the AWS-copilot-fargate-vapor-mongo guide (notice the difference in the title and my keyword link). I'll explain how I deployed a custom service, but with Postgres storage type.


$ download code 


AWS Copilot with Fargate


I believe the goal of a blog post is to offer some of the caveats that the documentation hides. As a result, to build an app with AWS copilot CLI go to https://aws.github.io/copilot-cli/

 

Internals


I choose to use PostgreSQL for my backend application and the Fluent ORM. On the AWS side, this is Aurora Serverless RDS.


The Environment.APICLUSTER_SECRET that the storage infra type sets for you have the following structure (This is a Swift struct from a string/data)

struct APICluster: Codable {
    var dbClusterIdentifier: String
    var password: String
    var dbname: String
    var engine: String
    var port: Int
    var host: String
    var username: String
}

You will get this type at runtime, in contrast to how these values get configured if you were to use MongoDB. You will need to inject the MongoDB values in the pre-packaging phase.

 

CI/CD with Docker

A site I used as a reference tmac's SPM posts


Doing this on arm64 vs. GitHub Actions (CI/CD) vs. copilot Infrastructure CLI toolbox took me just a few days to understand. As always, I aim to make it simple, intuitive, and user-friendly.


In my local, I* run


docker build --ssh github=$HOME/.ssh/id_ed25519 -t idelfonsog2/stranded-api .

docker tag idelfonsog2/stranded-api:latest ${{ secrets.ECR_REPO_URL }}

docker push ${{ secrets.ECR_REPO_URL }}

In GitHub Action, it* runs.


- name: Build Docker Image
        run: |
          docker build --ssh github=$HOME/.ssh/id_ed25519 -t idelfonsog2/stranded-api .
          docker tag idelfonsog2/stranded-api:latest ${{ secrets.ECR_REPO_URL }}
          docker push ${{ secrets.ECR_REPO_URL }}
          
      - uses: ksivamuthu/aws-copilot-github-action@v0.0.1
        with:
          command: install

      - name: Copilot Deploy
        run: |
          copilot svc deploy --name api --app stranded --env dev

Freebie:

convert the following file to .yaml

ci
.txt
Download TXT • 2KB

Edit the Build Docker Image job per your image repository!

 

Result


I deployed my copilot application. ECS requires your service/task to have a GET / for health checks that returns a 200 status

import Vapor
...
app.get("")  { _ in HTTPStatus.ok }

response:

200

bottom of page