Create AWS API Gateway

1. Go to AWS API Gateway console.

2. In the left sidebar,

  • Choose APIs.
  • In the REST API section, click Build.

0001

3. In the API details section,

  • Select New API.
  • For API name, enter awsome-books.
  • For API endpoint type, select Regional.
  • Click Create API.

0002

4. Click Create method.

0003

5. In the Method details section,

  • For Method type, select ANY.
  • For Integration type, select VPC link.
  • Turn on VPC proxy integration.

0004

  • For HTTP method, select ANY.
  • For VPC link, select [Use stage variable] and enter ${stageVariables.vpcLinkId}. You define the vpcLinkId stage variable after deploying the API to a stage and set its value to the ID of the VpcLink.
  • For Endpoint URL, enter the Network Load Balancer’s DNS name you have noted down in step 12 in 8. Create Network Load Balancer.

0005

6. Scroll down to the bottom, click Create method.

0006

7. Click Deploy API.

0007

8. In the Deploy API modal,

  • For Stage, select *New stage*.
  • For Stage name, enter prod.
  • Click Deploy.

0008

9. Under the Stage details section, note the resulting Invoke URL. You need it to invoke the API. Before doing that, you must set up the vpcLinkId stage variable.

0009

10. Scroll down to the bottom, in the Stage variables tab, click Manage variables.

00010

11. In the Stage variables section, click Add stage variable.

00011

  • For Name, enter vpcLinkId.
  • For Value, enter the VPC Link ID you have noted down in step 6 in 9.1 Create VPC Link.
  • Click Save.

00012

12. To view the results, use the URL you obtained in step 9. If you try to invoke more than once, you should see 2 internal IP addresses in 2 seperate subnets (Yours could be different from mine).

00013

00014

You can access the internal Network Load Balancer in a totally private VPC via AWS API Gateway with the VPC Link setting, which is incredible!