Thiago's Space Blog

Just another blog, this one about my learnings as I join the Space Industry as a software engineer.

View on GitHub
6 January 2022

Fargate

Deploy gRPC/REST server with Fargate

Fargate is a relatively easy option to deploy/run containers in AWS. The buzzword here is Serverless: you worry about your application and leave the infrastructure details to the cloud services provider. Lambda is the other serverless computing option AWS provides.

Side note: I actually worked on GCP Serverless from ‘17 to ‘19. The counterparts to Fargate and Lambda in GCP are Cloud Run and Cloud Functions.

I just deployed the gRPC example we’ve been discussing using Fargate, and you can now access the REST API via the Application Load Balancer URL:

> curl -X POST \
    api-thiago-pub-lb-181830448.us-east-1.elb.amazonaws.com/v1/response \
    -d '{"message": "greetings"}'

{"message":"Hello I am up and running received \"greetings\" message from you","received":true}

The next step in this journey is to create a new record for domain thiago.pub so we can access the REST API via api.thiago.pub. Something else I might attempt is making the gRPC interface publicly available. That will be a new learning experience, and you can bet I’ll be sharing it here.

Deploy/run gRPC example using Fargate

1 Upload your image to Elastic Container Registry (ECR).

2 Create a EC2 Security Group with the appropriate inbound rules.

3 Create a EC2 Target Group for the REST proxy (port 8081).

4 Note you have to specify how the Target Group will perform Health checks; I simply configured it to accept a 404 as a valid response for the check (hacky), instead of implementing a Health check handler for the REST proxy.

5 Create a Internet-facing Application Load Balancer using the Security Group and Target Group created above.

6 Create a Elastic Container Service (ECS) cluster (no image for this step since I re-used a cluster created for a different project).

7 Create a ECS Task Definition using the image you uploaded in 1; this is were you define the appropriate Port Mappings to ensure the relevant services within the running container are accessible.

8 Create the new service within the cluster, using the Security Group, Task Definition and Target Group created above.

And voilà! There’s a lot more details than what’s covered here, but the beauty of it is that AWS provides a TON of good documentation, and you can’t really break anything in an unrecoverable way as you grope your way around. So have at it!