Site iconAxway Blog

How to Run your API Builder Docker Image on AWS EC2

This guide describes how to run your API Builder Standalone Docker image on an AWS EC2 instance. This is suitable for test and development but for production you will want to stand up a scalable, high availability AWS environment. We’ll discuss these options in future blog posts.

The steps we will follow are:

Note that everything we are covering in this blog post can be accomplished with the AWS Free Tier.

Let’s get started.

Create and Test Your API Builder 4.0 Docker Image

Start from API Builder 4.0 Standalone – From Zero to Dockerized Microservice and create and test your Docker image.

In the prior blog post, we ran our Docker image locally using the following command:

docker run --name lbdemoapi -p 80:8080 -e MONGO_PWD= lbdemoapiimage

Note: AWS can expose port 80 for http traffic so I changed command above to map host port 80 to API Builder port 8080. You can test your API using curl ‘https://localhost:80/api/mongo/dog’

Publish Your Docker Image to Docker Hub (or your Docker Repository)

Now that we have a working Docker Image, we can publish it to a repository so it is available to be installed on other machines. The steps are as follows:

Create an AWS EC2 Linux Instance and SSH into it

Now that we have our Docker image published, let’s go create an AWS EC2 Linux instance to run our Docker image on. The steps are as follows:

Install Docker

Now we need to install Docker on this Linux instance using the instructions here

sudo yum update -y

sudo yum install -y docker

sudo service docker start

sudo usermod -a -G docker ec2-user

exit

SSH back in to the instance and make sure the ec2-user can run Docker by executing the following command:

docker info

If you get a valid response (as follows) then Docker was installed properly

Run The API Builder Docker Image

Test your APIs

Get your instance Public IP address or public DNS entry form the AWS Portal and test your API from your host computer in terminal (or from Postman or the Browser, …).

Note that your IP Address/DNS entry will change if you stop and restart your instance. Use Elastic IP to insure that the IP address/DNS entry doesn’t change.

curl 'https://<instance IP or public DNS address>/api/mongo/dog'

You can get your instance Public IP Address or Public DNS entry from the AWS Console EC2 Instance page on the bottom of the page when you select your instance as shown below:

Test your API from your host computer in a terminal

Note that if your instance does not show a public DNS, you can enable this as follows:

Summary

In this blog post, we saw how easy it is to deploy our API Builder Docker image on AWS EC2. In future blog posts, we’ll look at leveraging AWS for auto-scaling and high availability.

It is worth noting that our API should be secured using the Axway API Gateway. You can read more about Axway API Gateway here.

Exit mobile version