How to invoke a private REST API (created with AWS Gateway) endpoint from an EventBusRule?
I have setup the following workflow:
- private REST API with sources
/POST/event
and/POST/process
- a
VPCLink
to anNLB
(which points to anALB
pointing to a microservice running onEKS
) - a
VPC endpoint
with DNS namevpce-<id>-<id>.execute-api.eu-central-1.vpce.amazonaws.com
withPrivate DNS enabled
- an EventBridge
EventBus
with a rule that has two targets: 1API Destination
for debugging/testing and 1AWS Service
which points to my private REST Api on the source/POST/process
- all required
Resource Policies
andRoles
- all resources are defined within the same AWS Account
The designed worflow is as follows:
- invoke
POST/event
on the VPC endpoint (any other invocation is prohibited by theResource Policy
) with anevent
payload - the API puts the
event
payload to theEventBus
- the
EventBusRule
is triggered and sends theevent
payload to thePOST/process
endpoint on the private REST API - the
POST/process
endpoint proxies the payload to a microservice running on EKS (viaVPCLink
>NLB
>ALB
>k8s Service
)
What does work so far:
- invoking
POST/event
on the VPC endpoint - putting the
event
payload to theEventBus
- forwarding the
event
payload to theAPI Destination
set up for testing/debugging (it's a temporary endpoint on https://webhook.site) - testing the
POST/event
andPOST/process
integration in the AWS Console (the latter is verified by checking that theevent
payload reaches the microservice on EKS successfully)
That is all single steps in the workflow seem to work, and all permissions seem to be set properly.
Whad does not work is invoking the POST/process
endpoint from the EventBusRule
, i.e. invoking POST/event
does not invoke POST/process
via the EventBus
, although the EventBusRule
was triggered.
So my question is: How to invoke a private REST API endpoint from an EventBusRule?
What I have already tried:
- change the order of the
EventBusRule targets
- create a Route 53 record pointing to the
VPC endpoint
and treat it as an (external)API Destination
- allow access from anywhere by anyone to the REST API (temporarily only, of course)
Remark on the design:
I create two endpoints (one for receiving an event
, one for processing it) with an EventBus in between because
- I have to expect a delay of several minutes between the
Event Creation/Notification
and the successfulEvent Processing
- I expect several hundred
event sources
, which are different AWS and Azure accounts - I want to keep track of all events that reach our API and of their successful processing in one central EventBus and not inside each AWS account where the event stems from
- I want to keep track each failed event processing in the same central EventBus with only one central DeadLetterQueue
Private API Gateway endpoints can only be called from within the VPC they are configured in. EventBridge Targets can't point to private resources in a VPC. This means that you can't directly invoke your private API from EventBridge.
You can work around it by invoking a Lambda function instead. The function is attached to the VPC and it can make calls to the API.
Good point. Seems like a bug. Will report it internally.
Thank you @Uri
:+1:
Relevant questions
Lambda (private subnet) <- ingress request< - gateway
Accepted Answerasked 4 months agoCalling Private API from Lambda in VPC
Accepted Answerasked 2 years agoPrivate Route 53 to API Gateway
Accepted Answerasked 5 months agoVPC Interface Endpoints and API Gateway called from Lambdas
Accepted Answerasked 6 months agoApiGateway to control an EC2 instance with load balancer running a FastAPI
Accepted Answerasked 2 months agoAccessing API Gateway both Public and Private endpoint
Accepted Answerasked a year agowhere does this vpc endpoint coming from
asked 4 months agoBuild a REST API with API Gateway private integration: Tutorial
Accepted Answerasked 3 months agoAmazon API Gateway Proxy - VPC Endpoint - NLB - Private DNS - Self-signed SSL
Accepted Answerasked 2 years agoHow to invoke a private REST API (created with AWS Gateway) endpoint from an EventBusRule?
Accepted Answerasked 2 months ago
Hi @Uri, thank you for your response.
If your explanation is right (and I do not doubt it), then I wonder why the h**l AWS allows me to select a private REST API from the Drop-Down menu as a target when I select
AWS Service
as the target type???I used to rely on the preselection of available resources in the Drop-Downs, in the sense that it's impossible to create an incompatible configuration in the Amazon Console.