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
- Create an account or log in with your Amazon account.
- Register for AWS Free Tier: valid for 12 months from the subscription date.
- Select AWS support plan: AWS Support (Basic) is included.
- 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:
- Launch a Windows Virtual Machine with Amazon EC2
- 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
- Create a simple Echo API with editor.swagger.io
- Create Echo service in node.js. In Swagger, generate server and select node.js.
- 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.
- 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.
- Create a Dockerfile in the root of the folder that will build the docker image for us.
- Create a .dockerignore that defines which files should not be copied in the image.
- Run “docker build -t echo .” to build the image.
- Run “docker images” to see the available images.
- 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.
- 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.
- 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.
- Create repository under Repositories.
- Build, tag and push the Docker image as described in step 2.
- Create task definition. (use full name of your docker image in your repository)
- Run the task definition.
- Go to the task and get the public IP, open the public IP in the browser.