Using Amazon EC2 A1 Instances for running containers on Amazon ECS

Mani
3 min readAug 29, 2019

From https://aws.amazon.com/ec2/instance-types/a1/ — “ Amazon EC2 A1 instances deliver significant cost savings for scale-out and Arm-based applications such as web servers, containerized microservices, caching fleets, and distributed data stores that are supported by the extensive Arm ecosystem. A1 instances are the first EC2 instances powered by AWS Graviton Processors that feature 64-bit Arm Neoverse cores and custom silicon designed by AWS. These instances will also appeal to developers, enthusiasts, and educators across the Arm developer community. Most architecture-agnostic applications that can run on Arm cores could also benefit from A1 instances.”

Plus, we just announced that EC2 A1 instances are available in additional regions including Mumbai Region, Yeah !!

Given that running containerized microservices are a big target segment for A1 instances, I wanted to try them on AWS container services like Amazon ECS (on EC2) and Amazon Elastic Kubernetes Service (EKS)>

On Amazon ECS

Amazon Elastic Container Service (Amazon ECS) now supports using the Amazon Linux 2 (AL2) Amazon Machine Image (AMI) optimized for ECS, and also the Amazon EC2 A1 instance family, directly from the Amazon ECS console during cluster creation.

I created an ECS Cluster and made sure to select EC2 A1 instances as part of the cluster. If you have enabled access via SSH you can run some basic Linux commands to verify the processor type ..

Inside the A1 EC2 instance:

x64 processor in a1.medium

While you get the following in a normal x86 t2.micro:

x86 processor in a t2.micro

Once the cluster is created, running containers as ECS services on these instances is straightforward. I tested initially with an Task definition for an nginx image and it ran successfully ..

But, I was looking for an small application that can display the processor type of the host just for kicks ;-) as most lazy programmers do, I googled for an existing app and I found an awesome blog (though in Japanese) at https://qiita.com/hideaki_aoyagi/items/877e8316cbb35293dfb0

This blog has a small Go application that displays the hostname, operating system and processor architecture. I have added these files into my githib repo at https://github.com/cmanikandan/aws-ec2a1-containers . You can clone this repo and test it out ..

Dockerfile

FROM golang:latest AS builder
WORKDIR /tmp
ADD ./go-webserver-sample.go /tmp
RUN GOOS=linux CGO_ENABLED=0 GOARCH=arm64 go build -o go-webserver-sample .

FROM alpine:latest
COPY — from=builder /tmp/go-webserver-sample /bin/
CMD [“/bin/go-webserver-sample”]

The only change that I had to make from the original blog, was to add GOARCH=arm64 before doing the go build command.

The Go code:

package main

import (
“fmt”
“net/http”
“os”
“runtime”
)

func handler(w http.ResponseWriter, r *http.Request) {
hostname, _ := os.Hostname()
fmt.Fprintf(w, “<h1>Welcome Golang-WebServer!</h1>”)
fmt.Fprintf(w, “<h2>Hostname: %s</h2>”, hostname)
fmt.Fprintf(w, “<h2>OS: %s</h2>”, runtime.GOOS)
fmt.Fprintf(w, “<h2>Architecture: %s</h2>”, runtime.GOARCH)
}

func main() {
http.HandleFunc(“/”, handler)
http.ListenAndServe(“:8080”, nil)
}

Push the image to Amazon ECR, create a Task definition and create an ECS service.

Voila, I get the details of the underlying host via the ECS service when I call the ECS service ..

Go app on Amazon ECS with A1 Instances ..

On Amazon EKS:

There is an ongoing preview to run containers using EC2 A1 instances on a Kubernetes cluster that is managed by Amazon EKS.. More details are available at https://github.com/aws/containers-roadmap/tree/master/preview-programs/eks-ec2-a1-preview

Hopefully, in part 2 of this blog, I will post my experiences of running on EKS ..

Until then, bye and happy containerizing on A1 !!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Mani
Mani

Written by Mani

Principal Solutions Architect at AWS India, and I blog/post about interesting stuff that I am curious about and which is relevant to developers & customers.

No responses yet

Write a response