Real-Time Data Ingestion from External Sources into Databricks Using AWS Lambda and Webhooks

Co Author - Aditi Agarwal
Overview
The existing ingestion process is based on batch processing, resulting in at least three hours of delay before the availability of data that could be used for analysis once forms are submitted via Typeform. It had limited capabilities in terms of delivering insights, increased the overhead from scheduled polling, and generally reduced the scalability and responsiveness of the platform. However, the proposed solution was to build a data ingestion pipeline using the Typeform webhook to invoke AWS Lambda immediately after form submission. AWS Lambda saves the incoming data as raw JSON files in Amazon S3, where it becomes available for analysis in Databricks. This event-driven architecture eliminates the need for scheduled polling, enabling real-time data ingestion while reducing operational overhead and improving the scalability and responsiveness of the platform.
Understanding the Real-Time Ingestion Architecture
Prior to delving into how the implementation of this approach can be performed, it is important to understand how the architectural design can allow for the immediate ingestion of data. As the architecture utilizes an event-driven approach, all data processing is done automatically once created and not on a batch or update basis.
Ingestion Layer
When the data is obtained from the external source, Typeform, the ingestion process begins. As soon as a user submits a response, a webhook is triggered, initiating an event-driven workflow that invokes AWS Lambda. The Lambda function receives the incoming payload and transfers it to Amazon S3 in JSON format, where S3 serves as the raw data storage layer for the project. This architecture enables real-time data ingestion without relying on scheduled jobs or manual intervention, ensuring immediate, scalable, and efficient processing of incoming data within the AWS infrastructure.
Analytics Layer
The analytics and further processing are done using Databricks, which is connected to Amazon S3 through Unity Catalog. After that, the data is processed using Apache Spark for better and quicker analysis and decision-making.

Prerequisites
Before proceeding, make sure the following requirements are fulfilled:
- An active AWS account with access to:
- Amazon S3
- AWS Lambda
- API Gateway
- IAM
- A Databricks workspace with Unity Catalog enabled
- Required permissions to create:
- IAM roles
- S3 buckets
- Lambda functions
- API Gateway endpoints
- External locations in Databricks
- An external data source (such as Typeform) with webhook support enabled
- Basic understanding of JSON data format and HTTP requests
Step-by-Step Implementation
Step 1: Create an S3 Bucket for Data Storage
This bucket will store incoming webhook data as JSON files and act as the raw data layer.
- Go to the AWS Console
- Navigate to S3
- Click on Create bucket
- Configure:
- Bucket name: typeform-data-bucket
- Region: Select the same region for all services
- Click Create bucket

Step 2: Create IAM Role for Lambda
This role allows Lambda to write data to Amazon S3 and publish execution logs to Amazon CloudWatch for monitoring and troubleshooting.
- Go to IAM → Roles → Create Role
- Select:
- AWS Service → Lambda
- Click Next
- Attach the AWS managed policy:
- AWSLambdaBasicExecutionRole
- Enter role name: lambda-s3-role and click Create Role.
- Open the newly created role and navigate to: Permissions -> Add permissions -> Create inline policy.
- Select the JSON editor and paste the following policy to allow the Lambda function to write data to the target S3 bucket:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "WriteWebhookData",
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": "arn:aws:s3:::typeform-data-bucket/*"
}
]
}
Step 3: Create AWS Lambda Function with Signature
This function processes incoming webhook requests and stores data in S3.
- Go to Lambda → Create Function
- Select:
- Author from scratch
- Function name: typeform-handler
- Runtime: Node.js 24.x
- Under permissions:
- Choose existing role → lambda-s3-role
- Click Create Function
Environment Variables
Configure the following Lambda environment variables :
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import crypto from "crypto";
const AWS_REGION = process.env.AWS_REGION;
const BUCKET_NAME = process.env.BUCKET_NAME;
const TYPEFORM_SECRET = process.env.TYPEFORM_WEBHOOK_SECRET;
const s3 = new S3Client({ region: AWS_REGION });
function isValidSignature(signatureHeader, rawBody) {
const hash = crypto
.createHmac("sha256", TYPEFORM_SECRET)
.update(rawBody)
.digest("base64");
const expected = `sha256=${hash}`;
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signatureHeader || ""));
}
export const handler = async (event) => {
try {
const signature = event.headers["typeform-signature"];
const rawBody = event.body;
if (!isValidSignature(signature, rawBody)) {
return { statusCode: 401, body: JSON.stringify({ error: "Invalid signature" }) };
}
const body = JSON.parse(rawBody);
const command = new PutObjectCommand({
Bucket: BUCKET_NAME,
Key: `data-${Date.now()}.json`,
Body: JSON.stringify(body),
ContentType: "application/json",
});
await s3.send(command);
return { statusCode: 200, body: JSON.stringify({ message: "Stored in S3" }) };
} catch (error) {
console.error("Error processing webhook:", error);
return { statusCode: 500, body: JSON.stringify({ error: error.message }) };
}
};
- Click Deploy

Store the Typeform webhook secret in an environment variable (e.g., via AWS Secrets Manager or Lambda environment variables), and set it under Typeform → Webhooks → Add Webhook → Secret. Typeform signs each request with this secret in the Typeform-Signature header, so the Lambda function must verify it before processing the payload.
Step 4: Create API Gateway Endpoint
This will expose a public endpoint to receive webhook requests.
- Go to API Gateway → Create API
- Select HTTP API
- Add integration:
- Select Lambda → typeform-handler
- Configure route:
- Method: POST
- Path: /submit
- Deploy the API and copy the Invoke URL. The full webhook URL is the Invoke URL followed by the route path /submit.


Step 5: Configure Webhook in External Source with Signature Verification
- Open Typeform
Log in to your Typeform account and open the form from which you want to capture responses. - Go to Connect → Webhooks.
Inside your form dashboard, navigate to the “Connect” section and then select “Webhooks”. - Click on “Add Webhook”
Click the “Add webhook” button to create a new webhook connection. - Paste the API Gateway URL
Enter the full endpoint URL: the Invoke URL from Step 4 with /submit added to the end. If you paste only the Invoke URL without /submit, the request won’t match the route, and Typeform will get a 404 error. - Set the Webhook Secret
In the same webhook setup screen, enter a secret string in the Secret field. Typeform uses this to sign every request with an HMAC-SHA256 signature in the Typeform-Signature header. Store this same secret in AWS (e.g., a Lambda environment variable or Secrets Manager) - the Lambda function will use it to verify incoming requests are genuinely from Typeform, not a rogue actor sending directly to your public endpoint. - Save the Webhook
Click Save to activate the webhook. Now, whenever a user submits the form, the response will be automatically sent to your API Gateway in real time, signed for verification.

Step 6: Test the Pipeline
- Submit form response
- Go to S3 and refresh the bucket.
You should see a JSON file created under Objects.
Troubleshooting: If no file appears, check these two places:
Typeform → Connect → Webhooks → View deliveries: This shows each webhook request and the response code it got back. A 200 means Lambda received and stored the data. A 401 means the signature check failed, so make sure the secret in Typeform matches the one in Lambda. A 500 points to an error inside the Lambda function.
Amazon CloudWatch Logs: Go to Lambda → typeform-handler → Monitor → View CloudWatch logs (log group /aws/lambda/typeform-handler). The logs show every invocation and any errors, such as S3 AccessDenied caused by missing IAM permissions.

Step 7: Connect Databricks to S3 Using Unity Catalog
- Open your Databricks Workspace
- From the left sidebar, click on Catalog
- Select your Catalog
- Click on the Settings icon next to the catalog name
- Click on Create External Location
- Select the option: AWS Quickstart
- Enter the S3 bucket name and click Next
- When prompted, click Generate new token to create a personal access token (PAT), and copy it. The AWS CloudFormation stack uses this token to call the Databricks REST API and register the storage credential and external location in your workspace. Then click Launch in Quickstart.
- In AWS, a CloudFormation stack opens with the Databricks-generated template already filled in. Paste the PAT into the Databricks Personal Access Token field. The template creates an IAM role with access to the bucket and links it to a Unity Catalog storage credential.
- Check the acknowledgment checkbox: "I acknowledge that AWS CloudFormation might create IAM resources," then click Create Stack.
- Open a Databricks Notebook and run the following code. Note that this example uses Structured Streaming with a 10-second micro-batch interval to demonstrate near real-time ingestion. Organizations with low-volume workloads may consider less frequent triggers or scheduled processing to reduce compute costs:
s3_source_path = "s3://typeform-data-bucket/"
checkpoint_path = "s3://typeform-data-bucket/_checkpoints/typeform_raw_data"
table_name = "my_catalog.my_schema.typeform_raw_data"
df_stream = (
spark.readStream
.format("cloudFiles")
.option("cloudFiles.format", "json")
.option("cloudFiles.schemaLocation", f"{checkpoint_path}/schema")
.load(s3_source_path)
)
query = (
df_stream.writeStream
.option("checkpointLocation", checkpoint_path)
.trigger(processingTime="10 seconds")
.toTable(table_name)
)
query.processAllAvailable()
display(spark.sql(f"SELECT * FROM {table_name}"))
One thing to know about the paths above: the checkpoint directory sits inside the bucket that Auto Loader is monitoring. That works because Spark’s file listing ignores paths beginning with an underscore, so _checkpoints/ is skipped rather than ingested. If you would rather not depend on that convention, write the payloads under a prefix such as raw/ and point s3_source_path at the same prefix, keeping the checkpoint outside it.
Because the streaming query runs in the background, query.processAllAvailable() waits until every file currently in the bucket has been processed and written to the table before the SELECT runs. Unlike a fixed wait, this works even when the cluster is cold, or Auto Loader is inferring the schema for the first time. The stream keeps running afterward and picks up new responses every ten seconds. When you have finished testing, stop it with query.stop() so the cluster is not held open.

Challenges and Future Outlook
Even though this real-time data pipeline using AWS Lambda and webhooks offers great benefits in scaling and automation, there are some challenges and limits to think about, along with possible improvements for the future:
- Webhook Data Handling Variability: The data coming from outside sources through webhooks wasn't always in the same format. This meant the Lambda function needed extra work to properly handle both text and JSON data, so the incoming information could be processed reliably.
- IAM Permission Configuration: It was hard at first to set up the right IAM roles and permissions for Lambda to access S3.Small mistakes in the setup caused problems with storing data, and it took careful checking and testing to fix the access rules.
- Service Region Mismatch: There were issues when AWS services like Lambda and S3 were in different regions. To make everything work smoothly and prevent errors, all the services had to be in the same region.
- Small File Problem: Currently, every webhook call writes its own small JSON file (often about 1 KB) to S3. As submissions grow, this creates thousands of tiny files that increase S3 request costs, can run into request-rate limits, and slow Apache Spark down, because Auto Loader spends more time listing and opening files than reading data. A future improvement is to add Amazon Data Firehose between the Lambda function and S3. Lambda would still verify the Typeform signature, then send each payload to Firehose with PutRecord instead of writing straight to S3. Firehose collects the records and writes them to the raw/ prefix as larger combined files, for example every 60 seconds or every 5 MB, whichever comes first. Setting a newline delimiter between records keeps the output readable by Auto Loader as newline-delimited JSON. This cuts the file count sharply and improves Spark read performance, with only a short, configurable delay added.
- Streaming Compute Costs: Running a streaming query with a 10-second micro-batch trigger minimizes latency, but continuously running compute resources may not be cost-effective for low-volume workloads. Organizations should evaluate their latency requirements against operational costs, adjusting processing intervals or using scheduled batch ingestion where appropriate to achieve an optimal balance.
Conclusion
Replacing batch ingestion with a webhook-driven pipeline cuts data availability from three hours to seconds. Typeform triggers API Gateway and AWS Lambda, Lambda verifies the signature and writes raw JSON to Amazon S3, and Databricks ingests it through Unity Catalog and Auto Loader, with no scheduled polling.
To run this in production, add Amazon Data Firehose between Lambda and S3 to avoid the small-file problem. Also set the streaming trigger interval to match the latency the business actually needs, so compute cost stays proportionate. The same pattern works for any SaaS source that supports webhooks.
How v4c.ai can Help
v4c.ai is a Databricks services partner with a team of over 550 experts holding more than 850 certifications, and we have worked with over 300 clients across the retail, healthcare, manufacturing, and financial services sectors. We are experts at replacing batch processes with lower-latency processing using today's event-driven architecture that includes the use of serverless AWS Lambda services and Databricks Unity Catalog. Our service offerings include enabling your company to build an effective real-time ingest pipeline connecting your central Lakehouse system with other SaaS systems such as Typeform. This will include working on configuring IAM cross-account roles as well as ensuring efficient Delta Lake processing for streaming data.
By doing this, your organization will be able to create a seamless connection between your data lakes and other third-party systems while eliminating any kind of data silos.
More blog posts




