Skip to content

Latest commit

 

History

History

apigw-http-api-eventbridge-lambda-sls

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Amazon API Gateway HTTP API to Amazon EventBridge

This pattern creates an HTTP API endpoint that directly integrates with Amazon EventBridge

Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigateway-http-eventbridge-lambda-sls.

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

Requirements

Deployment Instructions

  1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:

    git clone https://github.com/aws-samples/serverless-patterns
  2. Change directory to the pattern directory:

    cd serverless-patterns/apigw-http-api-eventbridge-lambda-sls
  3. From the command line, use npm to install the development dependencies:

    npm install
  4. From the command line, use Serverless Framework to deploy the AWS resources for the pattern as specified in the serverless.yml file:

    serverless deploy --verbose

    The above command will deploy resources to us-east-1 region by default. You can override the target region with --region <region> CLI option, e.g.

    serverless deploy --verbose --region us-west-2
  5. Note the ApiEndpoint output from the Serverless Framework deployment process. You will use this value for testing.

How it works

This pattern creates an Amazon API gateway HTTP API endpoint. The endpoint uses service integrations to directly connect to Amazon EventBridge.

Once a new event is published to EventBridge WebApp custom event bus it is delivered to a Lambda function, which will simply log that event to EventLog. Lambda function is written in TypeScript and deployed to ARM64 architecture for demo purposes.

Testing

Sending a new test message to API Gateway endpoint

To test the endpoint first send data using the following command. Be sure to update the endpoint with endpoint of your stack.

curl --location --request POST 'ApiEndpoint output value' --header 'Content-Type: application/json' \
--data-raw '{
    "Detail":{
        "message": "This is my test"
    }
}'

Expected result

{"Entries":[{"EventId":"Event_UUID"}],"FailedEntryCount":0}

CloudWatch logs

Open AWS CloudWatch Console and navigate to /aws/lambda/apigw-http-api-eventbridge-lambda-sls-prod-logEvent log group. You should be able to see a new Event Stream with the Received Event information, and Event Message, logged into the stream.

Cleanup

  1. Delete the stack

    serverless remove --verbose
  2. Confirm the stack has been deleted

    aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'apigw-http-api-eventbridge-lambda-sls-prod')].StackStatus"

    Expected output

    [
        "DELETE_COMPLETE"
    ]

    NOTE: You might need to add --region <region> option to AWS CLI command if you AWS CLI default region does not match the one, that you used for the Serverless Framework deployment.


Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0