Unit 9 Cloud Pipelines Notes

Unit 9 — Lambda as Automation | DataSoSi
Cloud Data Pipelines · Unit 9 of 12 · Live Automation

Lambda as Automation

Move from understanding automation as a concept to configuring it in practice — create a real Lambda function in AWS, test it, and connect the full picture from file upload to Databricks workflow.

Unit 8 was the theory. This is where it becomes real. You will open AWS Lambda, create an actual function, test it, and see it respond — all without writing complex code. By the end of this unit, you will have touched every component of the automated pipeline: S3, Lambda, and Databricks.
4 Sections
Guided AWS Console Walkthrough
Minimal Coding — Maximum Understanding
1234 5678 9 101112

Learning Objectives

  • Explain what a Lambda function is and what it contains — in plain language, without deep coding knowledge
  • Create a real Lambda function in the AWS console using the pre-built starter template
  • Read and understand the starter code that AWS generates — identifying what each part does
  • Create a test event, run the function, and interpret the output that confirms automation worked
  • Simulate the Databricks side of the trigger in a notebook and trace the complete end-to-end flow
Four sections. Select individually or expand all.

In Unit 8 you learned that Lambda is a trigger — it detects events and starts other services. But Lambda itself is a function, and functions can feel intimidating if you have not encountered them before. This section removes that anxiety before you touch a single line of code.

Everyday Analogy — The Out-of-Office Reply

When you set up an out-of-office reply in your email, you define a simple rule: “If someone sends me an email while I am away, automatically send them this message.” You write the message once. You do not need to be present when it fires. Every incoming email triggers it automatically. A Lambda function works exactly this way — you define a small piece of logic once, and AWS runs it automatically every time the specified event occurs. You are not manually present for any of it.

The Anatomy of a Lambda Function

When you create a Lambda function, AWS generates starter code automatically. Here is the code you will see — and what every part of it means in plain language:

AWS Lambda Starter Code Python 3.x
def lambda_handler(event, context):
    return {
        ‘statusCode’: 200,
        ‘body’: ‘Pipeline Triggered’
    }
def lambda_handler Defines a function named lambda_handler. AWS automatically calls this exact function every time a trigger fires — it is the front door Lambda always knocks on. You do not choose the name; AWS expects it.
(event, context) Two pieces of information AWS passes in automatically. event contains details about what triggered the function — for an S3 trigger, this would include the file name and bucket. context contains runtime information like the function’s name and how long it has been running.
return { … } The function’s response — what it sends back after completing. In a real pipeline, this response confirms success and could include details about which Databricks job was triggered.
‘statusCode’: 200 A standard web response code meaning “everything worked correctly.” 200 is the universal signal for success — the same code your browser receives when a website loads without errors.
‘body’: ‘Pipeline Triggered’ The human-readable message returned by the function. This is what you will see in the test output — confirmation that the function ran and the pipeline trigger was sent successfully.
You Are Observing, Not Engineering

In this unit you are reading and understanding code that AWS wrote for you — not writing Lambda functions from scratch. The goal is to understand what the function does when it runs, not to memorize its syntax. In real business environments, Lambda functions for standard pipeline triggers are almost always adapted from templates exactly like this one.

Everything in this section happens inside the AWS console — no command line, no complex configuration. Follow each step in order. The goal is to have a working Lambda function that responds when tested.

Part 1 — Open Lambda
1
Log into AWS
Go to aws.amazon.com and sign in. You land on the AWS Management Console — the central dashboard for all services.
2
Find Lambda
In the search bar at the top, type Lambda and click the result. This opens the Lambda dashboard — a list of all functions in your account. It will be empty right now.
Part 2 — Create the Function
1
Click “Create function”
The orange button in the top right of the Lambda dashboard. This opens the function creation form.
2
Select “Author from scratch”
This option is selected by default. It gives you a blank function with starter code — exactly what you need for this unit. Do not select a blueprint or container image.
3
Name the function
Enter datasosi_pipeline_trigger as the function name. Names must use only letters, numbers, hyphens, and underscores — no spaces. This name describes exactly what the function does: it is the trigger for the DataSoSi pipeline.
4
Set the runtime
In the Runtime dropdown, select Python 3.x (choose the most recent version available — for example, Python 3.12). This tells Lambda which language the function is written in. Since you are already familiar with Python from the Databricks notebooks, the starter code will feel recognizable.
5
Click “Create function”
Leave all other settings as default. AWS creates the function and takes you to the function detail page. You will see the starter code in the inline code editor — the same code annotated in Section 1.
What Just Happened

AWS has created a small programme that lives in the cloud and waits. Right now it has no trigger attached — nothing will call it automatically yet. That is like hiring a receptionist and giving them a script, but not yet connecting the phone line. The function is ready; the event source that rings it will be configured when you connect S3 in your full pipeline. For now, you will test it manually.

Part 3 — Explore the Function Page

Before testing, take two minutes to explore the function page. The following areas will matter in later pipeline work:

AreaWhat It IsWhen You Use It
Code sourceThe inline editor showing your function’s codeTo view or modify what the function does when triggered
Configuration tabSettings for triggers, environment variables, permissions, and timeoutWhen connecting an S3 trigger or adjusting how long the function is allowed to run
Test tabA built-in tool to manually send a fake event to the functionTo verify the function works correctly before connecting a real trigger
Monitor tabLogs and metrics showing every time the function ran, how long it took, and whether it succeededWhen diagnosing problems in a live pipeline — this is where you look when something goes wrong
Part 4 — Create a Test Event and Run It
1
Click the “Test” tab
At the top of the function page. This opens the test configuration panel.
2
Create a test event
Select Create new event. Name it pipeline_test. Leave the event JSON as the default — it is a sample payload that represents a generic event. In a real pipeline, this would contain the S3 file details. For this test, the default is sufficient. Click Save.
3
Click “Test” to run the function
AWS executes the function using your test event as the trigger. Within a second or two, the results panel appears below the code editor.
4
Read the output
You will see a green success banner and the function’s response body. Look for “Pipeline Triggered” and a status code of 200. This confirms the function ran correctly.
What “Pipeline Triggered” Means

Seeing “Pipeline Triggered” in the output is the Lambda function confirming it ran successfully. In a real production system, this response would also contain information about which Databricks job was launched, the job ID, and a timestamp. For this course, the message itself is enough — it proves the automation mechanism is working. The function ran without a person pressing a specific “process file” button; AWS ran it in response to the test event.

Lambda’s job ends the moment it starts Databricks. Everything that follows — reading the file, cleaning the data, writing the output table — is Databricks’ responsibility. This cell simulates that handoff moment: the instant Databricks receives the signal from Lambda and begins its work.

Python Databricks — Receiving the Lambda Signal
print(“Databricks workflow started by Lambda”)
Expected Output
Databricks workflow started by Lambda
What This Represents

In a fully connected pipeline, this print statement would not be typed manually — it would appear automatically in the Databricks job logs the moment Lambda triggered the notebook. It is the first log line of every automated run: confirmation that the trigger was received and processing has begun. Everything that follows in the notebook — reading from S3, cleaning, writing the output table — is the work that runs after this confirmation. You have already built all of those steps in Units 5, 6, and 7. This cell is simply the starting gun.

The Complete End-to-End Flow — All Components Active
CSV
Business file uploaded to S3 raw/ folder
Unit 3 — the entry point of every pipeline run
Done
↓
λ
AWS Lambda detects the S3 upload event
This unit — your datasosi_pipeline_trigger function fires automatically
Now
↓
NB
Databricks notebook starts running
Lambda passes the file details — Databricks reads, cleans, and transforms the data
Now
↓
OUT
Clean output written to Delta table
Unit 7 — final_sales_output available for dashboards and reports
Done
The Full Picture

You have now built or simulated every stage of the pipeline. The S3 bucket exists (Unit 3). The notebook logic exists — reading (Unit 5), cleaning (Unit 6), writing output (Unit 7). Lambda now exists (this unit). What remains is connecting them so that uploading a file to S3 triggers Lambda, which triggers the notebook, which runs automatically. Units 10 and 11 address scheduling and monitoring that complete connection.

Lambda is not just a convenience tool — it is the foundation of a design philosophy called event-driven architecture. Understanding why this matters helps you see the broader value of what you are building.

Everyday Analogy — The 999 Emergency Line vs. A Daily Check-In

Imagine if, instead of calling 999 in an emergency, you had to wait until a scheduled 6 PM daily check-in when an operator would ask “did anything happen today?” For fraud detection, medical alerts, and supply chain disruptions, the delay between event and response is the difference between catching a problem early and discovering it too late. Event-driven systems eliminate that delay — they respond the moment something happens, not at the next scheduled window.

What Event-Driven Automation Enables
Immediate Response
A fraud alert system that processes transactions the moment they occur — not hourly or daily — can flag suspicious activity before a second fraudulent transaction takes place. Speed of response is only possible with event-driven triggers.
No Wasted Compute
Lambda only runs when triggered. A scheduled job runs at its appointed time whether data has arrived or not — consuming resources even when there is nothing to process. Lambda’s pay-per-use model means you only pay for what actually happens.
Scales Automatically
If 50 files arrive simultaneously, Lambda launches 50 parallel executions — one per file. A scheduled job would process them sequentially, taking 50 times as long. Event-driven systems handle volume spikes naturally without configuration changes.
Loosely Coupled
Lambda sits between services without either side needing to know about the other. S3 does not know Databricks exists. Databricks does not know how files arrived. Lambda is the invisible connector — replace either end and Lambda still works. This flexibility makes systems much easier to maintain and update.
Lambda Has Limits — Know When to Use It

Lambda functions have a maximum execution time of 15 minutes. They are ideal for lightweight triggering tasks — detecting an event and starting another service. They are not appropriate for long-running data processing jobs, which is precisely why Databricks handles the heavy lifting. Use Lambda for what it is designed for: fast, event-driven reaction. Use Databricks for what it is designed for: scalable data processing.

Knowledge Check

Five questions covering Unit 9. Select the best answer for each question.

1. In the Lambda starter code, what is the role of the event parameter in lambda_handler(event, context)?

2. What does a status code of 200 in the Lambda response mean?

3. Why is Lambda not appropriate for running the full data cleaning and transformation logic?

4. If 50 files arrive in S3 at the same moment, how does an event-driven Lambda system handle them?

5. In this unit’s Databricks simulation cell, what does the print statement represent in a real automated pipeline?

Unit 9 Summary

What you covered in this unit

Lambda Function

A small piece of cloud-hosted logic that runs automatically when triggered. AWS generates starter code — you observe, configure, and test it rather than writing from scratch.

lambda_handler

The entry point AWS always calls when a trigger fires. It receives event details and returns a response confirming whether the function ran successfully.

Test Events

Built-in AWS tools that send a simulated trigger to a Lambda function — allowing you to verify it works correctly before connecting a real event source like S3.

Event-Driven Design

Systems that respond to events rather than fixed schedules — enabling immediate reactions, automatic scaling, and resource efficiency that scheduled jobs cannot match.

AWS Lambda Lambda Function lambda_handler event parameter context parameter statusCode 200 Test Event Author from Scratch Event-Driven Architecture Serverless Pipeline Trigger