AWS API Gateway private integration with HTTP API and a VPC Link

 AWS API Gateway private integration with HTTP API and a VPC Link


A. Create the ALB:- 

1.Create it as an INTERNAL facing ALB. We don’t want to expose it to the internet.

2.There is only one listener on port 80 (This is the default).

3.Security Group that is created/assigned to the ALB can be fairly open for now (accept HTTP on TCP port 80 from anywhere).

4.In Step 4 of the wizard, the Target Group should have a target type as INSTANCE. Assuming that your EC2 is handling requests on port 80, 

you can keep the rest of the parameters as default. 

5 you can register your EC2 instance. allow security group 80 port.



B. Create a VPC Link:-

1.From the EC2 console, add Security Group for the VPC Link. this can be pretty open for now, with HTTP traffic on port 80 allowed from anywhere.

2.While you are there, alter the ALB SG to accept traffic only from the VPC Link SG, only on port 80.

3.From the API Gateway console, create a new VPC Link for HTTP APIs. Choose the subnets in both AZs as before (the same subnets that were chosen during the ALB creation). 

Assign the recently created SG to it. It should take about 2–3 minutes to be provisioned.



C. Create an HTTP API

1. No need to add any integration in Step 1, we will do it later (private integrations can only set up after the creation of the API)

2. Same with configuring routes in Step 2. Skip it, we will do it later. You cannot set up routes without defining integrations

3. Use all default values in Step 3 for stages. Note that there is a default stage, and it configured for auto-deployment.

4. Review and click on CREATE.

Your new API should be ready.


Let's create the route.

Click on the API name to get to the details page for this new API (if not already there)

Click on routes in the left nav bar and click on CREATE. Use default values of ANY for the method, and / for the route.


Now we will attach an integration to this route

Click on the route on the left side of the screen, and click on the CREATE AND ATTACH INTEGRATION button on the right.

Choose Private Resource, and then ALB/NLB

Choose the ALB that we had configured earlier, with the default listener on port 80

Lastly, choose the VPC Link that we had configured, and click CREATE.


At this point, you should be able to use the Invoke URL of the API to make a call to your EC2, which is now behind an APIG/ALB pair connected with a VPC Link

Comments

Popular posts from this blog

How to install and configure OSSEC server and client

How to install nuke in windows 10 and windows 11,Installing Nuke on Windows, Install Nuke on Windows

Autodesk Maya 2024 Install Windows 11