Getting started with Tyk on AWS

AWS is one of the most popular cloud platforms and getting started with Tyk on it has never been easier!

For this demonstration we will set up an EC2 instance, deploy Tyk using the tyk-pro-docker image via docker, bootstrap the dashboard, and create our first endpoint. By the end of this tutorial you’ll have a working version of Tyk that you can use to explore all of Tyk’s features!

To follow along you will need:

  • An active AWS account
  • A terminal to run commands in

Step 1: Create and launch your EC2 instance

Log into the AWS Management console and select ‘Launch a virtual machine’

Click “Select” on the Amazon Linux 2 AMI image (or whatever machine you’d prefer)

For instance type, select ‘t2.micro’ (or whatever type you’d prefer) 

 

For instance details we will take the defaults, and then click ‘6. Configure Security Group’ along the top bar on the screen.

Once at the Configure Security Group screen, we will name the security group “poc-open-group” and set the Type to “All traffic”, then set “Review and Launch”.

Check to make sure all your details are correct, and click “Launch”.

To log into the EC2 instance you’ll need a key pair. If you have an existing one you can use it but for our purposes we will generate a new one by selecting “Create a new key pair” and downloading the private key file. Don’t lose this file since you’ll need it to log into the VM! After the key is saved, click “Launch Instances”.

Now you’ll see that AWS is launching your instance! Now click “View Instances” so we can head to the dashboard.

You should now see your instance starting up and running. Once the instance status is listed as “running” we can begin to move onto installing Tyk onto it.

Step 2: Installing Tyk on our new AWS instance!

Now that we have an instance up and running, let’s log into it. Bring up your favourite terminal and run the following command: 

ssh -i yourkey.pem ec2-user@public-ec2-ip

yourkey.pem = path to your saved AWS key

public-ec2-ip = the public IP of your new EC2 instance (which can be found on instance dashboard screen)

Once you run the above command you’ll see this screen asking you if you want to connect to the instance. Type “yes” and press enter to log into the instance.

NOTE: If you get the following error when trying to log into the instance then you’ll need to set permissions on the private key file.

To do that, you’ll want to run sudo chmod 600 path/to/file.pem

At this point you have successfully logged into the system. You should see the following screen now displaying in your terminal:

We are now at the point where we will start to install the required components on the instance.

First, we update yum using:

sudo yum update -y

Next, we install git using:

sudo yum install git -y

Then we install docker, start, and configured the service using:

sudo yum install -y docker
sudo service docker start
sudo usermod -aG docker ec2-user
sudo su
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

After all of the above is set up, clone the Tyk Pro Docker repo from github using:

git clone https://github.com/TykTechnologies/tyk-pro-docker-demo

Then change to the newly created directory:

cd tyk-pro-docker-demo/

We then need to open up the Tyk Analytics configuration file so that we can add in our license key. I use nano to open it up using the following command:

nano confs/tyk_analytics.conf

Once the file is opened, scroll to the “license_key” field. Currently it will be blank.

Fill in your licence key and then use the control + X command to exit. Once you do this youll be prompted to save. Save the file by typing “Y” and pressing ENTER.

Nano will then ask you for the file name to write to which will already be populated with confs/tyk_analytics.conf. Press ENTER to save and exit.

At this point we want to bring up the stack. We do that using the docker-compose command like so:

docker-compose up -d

Once you press ENTER to run the command, the process will start to bring up the stack!

Once the process has brought up the stack you should see the following outlining that all components are up and running:

Now that we are up and running, let’s navigate to the dashboard to get started with Tyk! For this you’ll want to navigate to: https://<your aws instance public IP>:3000

Step 3: Configuring and using your new Tyk instance!

Once we have navigated to the URL in the previous step we should see the Dashboard Setup screen. Here you’ll want to fill out your details and click “BOOTSTRAP”.

After the bootstrap has completed, you then are taken into your new Tyk installation. From here navigate to the API Designer screen by clicking the APIs menu item on the left of the screen.

Once in the API Designer screen, under API Name enter “Test API”

Scrolling down on the screen, we will put our Target URL as “https://httpbin.org”

And lastly, at the bottom of the page under Authentication mode, select “Open (Keyless)” as your authentication type. Then click SAVE to create the endpoint.

Now you should see your first endpoint created under the Created APIs list on the next screen.

Step 4: Test the endpoint!

Lastly, using Postman (or another one of your favourite tools) we will send a GET request to our endpoint. The URL we will hit will be: https://<your aws instance public IP>:8080/test-api

Your results should look like this:

And there you have it, a new instance of Tyk up and running on AWS. Now you can easily start to discover some of the great features that Tyk has to offer! You can book a Tyk demo here.