How to access EC2 over HTTPS? [No ACM, No LB]

How to access EC2 over HTTPS? [No ACM, No LB]

Motivation / Why?

There are times that you just need to spin up a server quickly, experiment with something and etc… but you need an HTTPS secure connection. (e.g. WebRTC signaling calls, webhook requests)

Overview

In this article, we’re gonna use AWS API Gateway proxy in order to have an HTTPS connection for our API deployed on an EC2 instance.
There are some articles and tutorials out there which use a load balancer (ALB/NLB), VPC Link to achieve this same goal, but they would cost you extra money which we can easily avoid.

Steps / How?

۰٫ I assume you have an API deployed on an EC2 instance ready at xa.yb.zc.dd IP.
1. Log in to the AWS console and go to the API gateway service.
2. Click Create API
3. Choose HTTP API and click Build.
4. In the first step of creating an API Gateway, you need to add two integrations:
    1. HTTP | ANY | http://xa.yb.zc.dd
    2. HTTP | ANY | http://xa.yb.zc.dd/{path}

Creating API Gateway with HTTP Integration

The first one is for matching this route http://xa.yb.zc.dd without any trailing slash and the second one is for a catch-all/wildcard behavior.

۵٫ In the second step enter these values to map API gateway routes to integrations:
    1. $default | http://xa.yb.zc.dd
    2. ANY | /{path+} | http://xa.yb.zc.dd/{path}

Mapping API gateway routes to HTTP integrations

۶٫ Configure stages and create the API gateway

Yay!
Now you have an HTTPS proxy ready for your EC2 instance, hope this was helpful to you.
Please leave a comment if you had any challenges, issues setting this up, or a better solution to achieve this goal.

Published by

Mohammad Moallemi

Software Engineer by day, Technical Lead by night https://www.linkedin.com/in/mmoallemi99/

Leave a Reply

Your email address will not be published. Required fields are marked *