Below is a comprehensive README that includes details about your Lambda function and guidance on configuring an AWS EventBridge Rule to trigger it:
This project contains a Lambda function designed to be triggered by AWS EventBridge rules. The function processes events based on a given payload and interacts with an API endpoint using predefined types.
The Lambda function validates and processes payloads received from EventBridge. It supports a set of predefined types and makes either a GET or OPTIONS request to a configured API endpoint based on the event's type.
- Payload validation and parsing.
- Dynamic request type handling (
GET
orOPTIONS
). - Environment-based configuration for API endpoint and authentication.
- Comprehensive error handling and logging.
- Node.js
- AWS CLI (configured with appropriate permissions)
- Access to an AWS account
-
Deploy the Lambda Function: Use AWS Lambda console or AWS CLI to deploy the function to your AWS environment.
-
Set Environment Variables: Configure
API_BASE_URL
andAPI_AUTH_KEY
in the Lambda function's environment settings.
Run the test suite to ensure everything is functioning correctly:
npm install
npm test
To trigger this Lambda function using AWS EventBridge, you'll need to set up a rule. Below is an example CloudFormation template to configure an EventBridge rule.
AWSTemplateFormatVersion: "2010-09-09"
Description: "CloudFormation template for EventBridge rule 'spacecat-audit-trigger-test-dev'"
Resources:
EventRule0:
Type: "AWS::Events::Rule"
Properties:
EventBusName: "default"
Name: "spacecat-audit-trigger-test-dev"
ScheduleExpression: "cron(*/5 * * * ? *)"
State: "ENABLED"
Targets:
- Id: "rrl0zj4vhh2w3xtvp0ke"
Arn: "arn:aws:lambda:us-east-1:282898975672:function:spacecat-services--audit-scheduler:ci"
Input: "{\n \"type\": \"test\"\n}"
This template sets up a rule named spacecat-audit-trigger-test-dev
that triggers every 5 minutes and invokes the specified Lambda function with a payload containing { "type": "test" }
.
To deploy this rule:
-
Save the above template to a file, e.g.,
eventbridge-rule.yaml
. -
Use the AWS CLI to deploy the template:
aws cloudformation deploy --template-file eventbridge-rule.yaml --stack-name my-stack-name
-
Verify the rule in the AWS EventBridge console.
For support, issues, or enhancements, please open an issue in the repository. Contributions to this project are welcome via pull requests.
Apache-2.0