Getting started with AWS: Cloud Compute

AmazonWebservices Logo

AWS offers the following cloud compute products:

  • Lightsail for simple applications.
  • EC2 if you need control of the OS and virtual machine.
  • Elastic Beanstalk if you need virtual machines but want more automation done by AWS for you.
  • ECS, Kubernetes for ECS and Fargate if you want to utilize containers instead of virtual machines. Fargate offers serverless deployment of containers so you get more autiomation done AWS for your application.
  • Lambda function for serverless.

Sign up for an AWS Account

  1. Create an account or log in with your Amazon account.
  2. Register for AWS Free Tier: valid for 12 months from the subscription date.
  3. Select AWS support plan: AWS Support (Basic) is included.
  4. Create a billing alarm: alarm to trigger as soon as you go over the free tier, set When my total AWS charges for the month exceed to $.01.

Learn with 10-Minute Tutorials

The best way to get started with AWS is with the 10-minute tutorials. These are the tutorials that I completed and the services that I tried are included in the Free Tier:

  1. Launch a Windows Virtual Machine with Amazon EC2
  2. Run a Serverless “Hello, World!” with AWS Lambda

  3. Deploy Docker Containers on Amazon Elastic Container Service (Amazon ECS)

Keep in mind that some of steps and screenshots in the tutorials are outdated so you will have to figure out how it works.

Start Building with AWS

We are going to write a simple node.js API and deploy it to AWS.

Create the Echo server in node.js

Echo_Swagger
Echo API in Swagger
  1. Create a simple Echo API with editor.swagger.io
  2. Create Echo service in node.js. In Swagger, generate server and select node.js.
  3. Open the service in VS Code and install dependencies by typing “npm install” in the node terminal. Test by typing “npm start”. Open the URL in your browser and go to /docs.
  4. We implement a simple echo service in DefaultService.js

The source code for the server is on GitHub.

Run the server in a Docker file

Install Docker for Windows and start it on the local machine. If you happen to have a Windows 10 Home edition like me, then you either have to upgrade your Windows to the Pro edition or you could create an EC2 instance where you have AWS CLI, Docker, git and other packages.

  1. Create a Dockerfile in the root of the folder that will build the docker image for us.
  2. Create a .dockerignore that defines which files should not be copied in the image.
  3. Run “docker build -t echo .” to build the image.
  4. Run “docker images” to see the available images.
  5. Run the following command : “docker run -p:8080:8080 echo” to create and run a local container from your image. Now the API is running within the Docker container.
  6. Run “docker ps” to see the running containers.

The content of the Dockerfile:

FROM node:slim

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install

COPY . .

EXPOSE 8080

CMD ["npm" ,"start"]

Deploy the service to AWS

We want to test AWS Fargate so we took US East region as this is the only region currently that has Fargate.

  1. Go to AWS and select ECS. If you don’t have a cluster yet, create a default one using the sample-app to have AWS prepare all resources for you.
  2. Create repository under Repositories.
  3. Build, tag and push the Docker image as described in step 2.
  4. Create task definition. (use full name of your docker image in your repository)
  5. Run the task definition.
  6. Go to the task and get the public IP, open the public IP in the browser.
  7. Voila!
Image_Echo
Image repository
Fargate_Config1
Configuring the task definition
Fargate_Config2
Configuring the task size
Fargate_Config3
Container definition
Cluster_Task
Task running in the cluster
Container_Success
Success!