I have a couple of microservices running on EC2.

My intention is to use the AWS API gateway to allow internet access to the EC2 APIs.

Incoming Traffic is:
internet -> API Gateway -> EC2-server

I am planning to use a geedy HTTP Proxy on AWS Gateway. But I have 2 problems:

A) How can I address the EC2 in the "URL Endpoint" in the method integration? Can I somehow use the AWS private IP?

B) How do I configure the EC2 security group to allow an API gateway request into the EC2?


API Gateway is intended mostly for use with Lambda, so there are some limitations. For the easiest integration, you must have your microservice public and then authenticate between API Gateway and your service by some other means. This doesn't sound like what you want to do... I wouldn't want to make my non-public services public either!

In order to do what you're asking (API Gateway to private EC2 resources), you must set up a private integration. This looks very much like how AWS implements service endpoints for services like S3. Basically, you need to put an NLB in front of your service.Then you set up API Gateway to contact that endpoint via a VpcLink resource. The flow looks like this:

API Gateway -> VpcLink resource -> NLB -> Target Group -> EC2 instances

See also this question

  • I can't think of a way to put an ALB directly behind an NLB. The target of an NLB needs to be one or more instances or one or more fixed IP addresses, but the addresses on the front side of an ALB are dynamic. Apr 15 '18 at 23:54
  • Sounds like you would have to skip the ALB then, in which case you would lose some ability to health check your servers. You can still use target groups attached to an ECS service though. I will update my answer. Apr 16 '18 at 13:30
  • Easy as 1, 2, 10: aws.amazon.com/blogs/networking-and-content-delivery/…
    – Darragh
    Oct 3 '18 at 13:55

Note: I only have experience with Lambda, so I have never tested AWS API Gateway with plain HTTP backends yet... i.e. using it as a cloud-based nginx.

But according to @EdwardSamuel :

You can use AWS API Gateway (documentation).

API Gateway helps developers deliver robust, secure and scalable mobile and web application backends. API Gateway allows developers to securely connect mobile and web applications to business logic hosted on AWS Lambda, APIs hosted on Amazon EC2, or other publicly addressable web services hosted inside or outside of AWS. With API Gateway, developers can create and operate APIs for their backend services without developing and maintaining infrastructure to handle authorization and access control, traffic management, monitoring and analytics, version management and software development kit (SDK) generation.

API Gateway now supports HTTP Proxy integration for pass-through resources, so you don't need to describe your payload and query params explicitly (which was required previously).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.