Invoke AWS Lambda Functions Directly: No API Gateway Required

AWS Lambda is a popular serverless computing platform, but many users tend to rely on API Gateway to invoke their Lambda functions via HTTP requests. While API Gateway is highly integrated with Lambda, it can sometimes be overkill or incur additional costs depending on your specific use case. In this post, we'll explore an alternative way to invoke Lambda functions using RapidForge.

With RapidForge, you can avoid the overhead of API Gateway by using its webhook and periodic task features to invoke AWS Lambda functions directly from bash scripts. This approach provides a lightweight solution for running Lambda functions in response to HTTP requests or on a periodic schedule, without needing to build a full API Gateway integration.

Prerequisites

Step 1: Create a Webhook in RapidForge

To invoke a Lambda function via HTTP requests, start by creating a webhook in RapidForge.

  1. Log in to RapidForge.
  2. Navigate to the Webhooks section inside of the block.
  3. Click on Create New Webhook.
  4. Give the webhook a name (e.g., InvokeLambdaWebhook).
  5. Define the HTTP method (GET, POST, etc.) and URL path that will trigger this webhook.

Step 2: Write a Bash Script to Invoke Lambda

Once the webhook is created, you need to attach a bash script that will execute when the webhook is triggered. This script will use the AWS CLI to call the Lambda function. You can inject environment variables from the request context into this script to pass data dynamically.

Here’s an example bash script that invokes a Lambda function:


# You can set this as env variable a well
LAMBDA_FUNCTION_NAME="MyLambdaFunction"

# Call the Lambda function using AWS CLI, super simple!
aws lambda invoke \
  --function-name "$LAMBDA_FUNCTION_NAME" \
  --payload "$PAYLOAD_DATA" \
  /dev/stdout | jq -r '.body'

If you need to invoke Lambda functions on a schedule instead of via webhooks, RapidForge’s Periodic Tasks feature can help.

  1. Go to the Periodic Tasks section in RapidForge.
  2. Create a new task, specifying the schedule (e.g., every hour, every day, etc.).
  3. Attach a similar bash script to the task that uses the AWS CLI to invoke the Lambda function.
  4. Set environment variables as needed for the task.

This way, RapidForge will automatically trigger the Lambda function at regular intervals, without the need for an HTTP request or API Gateway. This approach is especially useful for those who prefer to avoid the complexity of setting up API Gateway or need more control over how Lambda functions are invoked.