AWS API Gateway AWS Service Integration

shows how an API Gateway endpoint can directly invoke an aws service like EventBridge, DynamoDB, etc. No lambda in the middle (reduces latency and costs).

HTTP REST APIs are the most common integration pattern. API Gateway is AWS managed service for creating REST APIs. It allows us to apply security, throttling, logging, etc. to our APIs. In some cases an API is simply a passthrough to a backend AWS service. The typical approach is to have API Gateway invoke a lambda, which then contains the code to call th target AWS service. If you don’t need to perform any additional logic to the request prior to calling the backend AWS service, you may be able to use an API Gateway AWS service integration, which can directly invoke the AWS service. This simplifies the architecture, reduces request latency and reduces costs.


Demo

Prerequisites

Running

# clone repo
git clone https://github.com/pfeilbr/aws-api-gateway-aws-service-integration-playground
cd aws-api-gateway-aws-service-integration-playground

# deploy
make deploy

# test
make test

example output

{
    "Entries": [
        {
            "EventId": "58c635b4-21aa-09d8-0ad3-0874b7dc0a39"
        }
    ],
    "FailedEntryCount": 0
}
# teardown
make teardown

Details

invoking the EventBridge PutEvents action with the request payload using the APIGatewayEventBridgeAccessRole role.

Integration:
    Type: AWS
    Credentials: !GetAtt APIGatewayEventBridgeAccessRole.Arn
    IntegrationHttpMethod: POST
    Uri: !Sub "arn:aws:apigateway:${AWS::Region}:events:action/PutEvents"

setting the required headers to invoke the PutEvents action

RequestTemplates:
    application/json: |
        $input.json("$")
        #set($context.requestOverride.header.X-Amz-Target ="AWSEvents.PutEvents")
        #set($context.requestOverride.header.Content-Type ="application/x-amz-json-1.1")

Resources