3 ways to deploy Apache APISIX on AWS (Part 1: AWS EC2)
Tags: aws, devops, apisix, docker
Published: 2022-06-28 05:04:37

[Apache APISIX](https://apisix.apache.org/) offers a centralized form of **API management** experience with full observability, security, and flexibility when you build and scale API programs in all cloud providers. By using cloud platforms, we can get the benefit from additional resource configurations and compute capabilities. As they provide pay-as-you-go pricing with no upfront expenses, you are able to plan, build and manage your global infrastructure at a high scale.

Throughout this series of blog posts, we will go over **3 most common ways** to **deploy and run** [Apache APISIX](https://apisix.apache.org/) API Gateway on one of the most comprehensive and widely used cloud computing platforms ☁️  [Amazon Web Services (AWS)](https://aws.amazon.com/about-aws/).

We discuss how to: 

✔️ Build and ship APISIX Docker image to [AWS EC2](https://aws.amazon.com/ec2/).
✔️ Use [Docker Compose](https://docs.docker.com/compose/) to deploy containerized APISIX to [AWS ECS](https://aws.amazon.com/ecs/).
✔️ Run APISIX on [AWS EKS](https://aws.amazon.com/eks/) with the help of [Helm](https://helm.sh/).

## Prerequisites

Below few required things you need to try all 3 methods of  deploying Apache APISIX API Gateway to AWS. 

➡️ **AWS account**. Set up an AWS account and create a IAM user if you haven't done yet follow the guide [AWS account setting-up](https://docs.aws.amazon.com/polly/latest/dg/setting-up.html).
➡️ **Docker Desktop** - you need also [Docker desktop](https://www.docker.com/products/docker-desktop/) installed locally to complete this tutorial. It is available for [Windows](https://desktop.docker.com/win/edge/Docker%20Desktop%20Installer.exe) or [macOS](https://desktop.docker.com/mac/edge/Docker.dmg). Or install the [Docker ACI Integration CLI for Linux](https://docs.docker.com/engine/context/aci-integration/#install-the-docker-aci-integration-cli-on-linux). 

## Build and ship APISIX to AWS EC2

To start with the simplest approach, in this post, we will look at how to run a single server in AWS by manually installing, running `APISIX` and `etcd` Docker containers on EC2.

[AWS EC2](https://aws.amazon.com/ec2/) is a favorite product that provides scalable virtual servers in the cloud while [Docker](https://www.docker.com/) makes it easy to run multiple applications on one server instance. AWS offers many advanced tools to deploy Docker services.

### Launch AWS EC2 Instance

Let's get started with launching EC2 instance for Apache APISIX. Login to your [AWS console](console.aws.amazon.com) and find EC2 service from the search bar and go to the EC2 dashboard. Click **Launch Instance**:

![Launch instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p3or1ionzevsiyydbhdz.png)
 
Next, to help you run EC2 successfully, select an Amazon Machine Image (AMI). For this example, I used Ubuntu Server with an ARM64 chip. Also, give a name for your EC2 instance.

![Ubuntu server](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/seiczfb8xqb763x39l3l.png)

You can leave other configurations as default. For detailed instruction, follow the [Get started with Amazon EC2 instance tutorial](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html).
 
Once you push the button **Launch Instance** and instance creation process starts. It can take a few minutes for the instance to be ready for you to connect to it. Check that your instance has passed its status in the **Status check** column. Then, Hit the **View Instances** button to access the EC2 Instances page.
 
![APISIX instance running on AWS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2epdcyxjcdfsg96dr3h2.png)

### Docker and Apache APISIX installation.

To run some commands, we need to connect to our Linux instance as the first step. There are several options you can see on [Connect to EC2 instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html) page. For the simplicity, we use [EC2 Instance Connect](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Connect-using-EC2-Instance-Connect.html). It provides a simple and secure way to access your instance directly from [the AWS EC2 console](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-connect-methods.html). 

To connect to your instance using the browser-based client from the Amazon EC2 console

1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

2. In the navigation pane, choose **Instances**.

3. Select the instance and choose **Connect**.

4. Choose **EC2 Instance Connect**.

5. Verify the user name and choose **Connect** to open a terminal window.

It opens another tab on your web browser with the terminal. 

![EC2 instance connect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oby5mwc0iu1uzjymghxi.png)
 
Next, we install Docker on the EC2 Instance:

``` bash
sudo apt-get update && sudo apt-get install docker.io
```

Now it’s time to run two containers for `APISIX` and `etcd`.

> **APISIX** uses [etcd](https://etcd.io/) to save and synchronize configuration. Before installing APISIX, you need to install `etcd` on your machine. It would be installed automatically if you choose the [Apache APISIX Docker compose](https://github.com/apache/apisix-docker) mode, you will learn more about on the next blog post _Use Docker Compose to deploy containerized APISIX to AWS ECS_.

Go ahead and install `etcd` first:

``` bash
sudo docker run -d --name etcd -p 2379:2379 -e ETCD_UNSUPPORTED_ARCH=arm64 -e ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 -e ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379 rancher/coreos-etcd:v3.4.16-arm64
```

☝️ Apache APISIX frequently releases the [latest version](https://apisix.apache.org/downloads) of the its **ARM64 image**, which can be deployed with one click using Docker.

Then, we start APISIX:

``` bash
sudo docker run -p 9080:9080 -p 9443:9443 --net=host --rm -d apache/apisix:2.14.1-alpine
```

With easy steps, we deployed Apache APISIX API Gateway to AWS EC2. The last step is to test it. 

### Verify Apache APISIX running

To verify if Apache APISIX is running in the cloud, we run the below `curl` command and check the response from APISIX's [REST Admin API](https://apisix.apache.org/docs/apisix/admin-api). You need to replace `EC2_PUBLIC_IP_ADDRESS` to your container instance's the **public IP address** or use the **public DNS name**. 

``` bash
curl "http://{EC2_PUBLIC_IP_ADDRESS}:9080/apisix/admin/services/" -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1'
```

The response indicates that APISIX is running successfully:

``` bash
{
  "count":0,
  "action":"get",
  "node":{
    "key":"/apisix/services",
    "nodes":[],
    "dir":true
  }
}
```

Here we go, Apache APISIX is up and running in AWS EC2 and responding to your requests 👏💪. 

## What's next

From this stage, you can create a [route](https://apisix.apache.org/docs/apisix/getting-started#:~:text=Copy-,Create%20a%20Route,-%23), [upstream](https://apisix.apache.org/docs/apisix/getting-started#:~:text=10%20by%20APISIX.-,Abstracting%20to%20Upstream,-%23) and manage the traffic to your backend services with the available [built-in plugins](https://apisix.apache.org/plugins) if you want to take advantage of more APISIX's features. You can provision other services on **AWS** with APISIX Docker compose like `prometheus`, `grafana` as well. Please stay tuned for more in the upcoming blog posts.

## Recommended content

➔ Watch Video Tutorial [Getting Started with Apache APISIX](https://youtu.be/dUOjJkb61so).

➔ Read the blog post [Overview of Apache APISIX API Gateway Plugins](https://dev.to/apisix/overview-of-apache-apisix-api-gateway-plugins-2m8o).

➔ Read the blog post [Centralized Authentication with Apache APISIX Plugins](https://dev.to/apisix/centralized-authentication-with-apache-apisix-plugins-30fo).

➔ Read the blog post [API Observability with Apache APISIX Plugins](https://dev.to/apisix/apis-observability-with-apache-apisix-plugins-1bnm).

➔ Read the blog post [Run Apache APISIX on Microsoft Azure Container Instance](https://dev.to/apisix/run-apache-apisix-on-microsoft-azure-container-instance-1gdk).


Community⤵️

🙋 [Join the Apache APISIX Community](https://apisix.apache.org/docs/general/community) 
🐦 [Follow us on Twitter](https://twitter.com/ApacheAPISIX)
📝 [Find us on Slack](https://join.slack.com/t/the-asf/shared_invite/zt-vlfbf7ch-HkbNHiU_uDlcH_RvaHv9gQ)
📧 [Mail to us](dev@apisix.apache.org) with your questions.