Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSC510 Lecture 11

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Avatar for Javier Gonzalez-Sanchez Javier Gonzalez-Sanchez PRO
September 27, 2026
15

CSC510 Lecture 11

AWS Lambda
(20260925)

Avatar for Javier Gonzalez-Sanchez

Javier Gonzalez-Sanchez PRO

September 27, 2026

Transcript

  1. CSC 5100 Modern Software Engineering Lecture 11. Serverless Architecture Dr.

    Javier Gonzalez-Sanchez [email protected] www.javiergs.info ffi o ce: 14 -227
  2. Where we are now? REST Client Java Service MQTT 3

    The next question: Must our service be running all the time just waiting for something to happen? 2
  3. Compare the execution models 5 Long-running Java service Lambda function

    main() EVENT connect handleRequest() WAIT DONE Process remains alive Invocation has a beginning and an end 5
  4. What is AWS Lambda? • No server for you to

    provision or keep running Event AWS Lambda runs your handler Result / Effect • AWS invokes the function when its trigger fires A managed compute service for running code in response to events. • You provide code + configuration; AWS manages execution Serverless ≠ no servers. It means you do not manage the servers. • Functions should be small, focused, and stateless between invocations Lambda runs the code that handles the request. 6 4
  5. What we actually built? AWS Lambda AWS Lambda GetCurrentTemperature Python

    GetCurrentTemperature Java 21 API Gateway • Lambda contains the code that reacts to an event. • API Gateway gives the Lambda an HTTP/REST-style entry point. • The route decides which Lambda integration receives the request. Client → HTTP GET → API Gateway → Lambda handler → JSON response 7
  6. Python Lambda: the simplest cloud reaction def lambda_handler(event, context): return

    { "temperature": 72.5, "unit": "F" } • No server loop. • No socket listener. • AWS invokes the handler when an event arrives. 9
  7. Java Lambda: same idea, packaged differently public class GetCurrentTemperature implements

    RequestHandler<Map<String,Object>,Map<String,Object>>{ public Map<String,Object> handleRequest( Map<String,Object> event, Context context ) { return Map.of("temperature",72.5,"unit","F"); } } mvn clean package target/temperature-lambda-1.0.jar 10
  8. API Gateway becomes the HTTP trigger Trigger = an event

    source that causes Lambda to run • Python Lambda shows API Gateway attached as a trigger. • Java Lambda also connected to an API Gateway 12
  9. Route + integration = the contract GET /temperature/current API Gateway

    Lambda integration JSON response 13 • The route is the public HTTP shape; the integration is the backend Lambda • Method: GET • Path: /temperature/current • Integration: GetCurrentTemperature Lambda • Stage: default • Automatic deployment: enabled
  10. Testing from the browser Python endpoint https://9nskxr38ti.execute-api.us-west-2.amazonaws.com/default/temperature/current Java endpoint used

    during setup https://2cwg3ubmbf.execute-api.us-west-2.amazonaws.com/default/CSC5100-GetCurrentTemperature Expected response {"temperature": 72.5, "unit": "F"} 14
  11. Java runtime con iguration: connect AWS to our class 15

    f edu.calpoly.temperature.GetCurrentTemperature::handleRequest
  12. How do we test a Lambda? 1. Unit Test 2.

    CI Test 3. Cloud Test 4. End-to-End local • fast • JUnit GitHub • mvn test deployed Lambda real event path Debugging should happen in levels 1–2 Do not make AWS the first place you discover a bug.. 17 CSC 5100 • Software Engineering 10
  13. Contract { { "team": "team03", "feature": "temperature", "payload": { "temperature":

    31.4 } "team": "team03", "feature": "temperature", "status": "HIGH" } } INPUT EVENT 18 CSC 5100 • Software Engineering EXPECTED RESULT 16
  14. Testing Lambda Locally: JUnit vs pytest Java → JUnit Python

    → pytest @Test void returnsCurrentTemperature() { GetCurrentTemperature h = new GetCurrentTemperature(); from lambda_function import lambda_handler def test_returns_current_temperature(): result = lambda_handler({}, None) Map<String,Object> result = h.handleRequest(Map.of(), null); assert result["temperature"] == 72.5 assert result["unit"] == "F" assertEquals(72.5, result.get("temperature")); assertEquals("F", result.get("unit")); Run locally: pytest } \ 19 23
  15. Level 3 — Test the deployed Lambda GitHub Actions AWS

    Lambda Actual Result PASS / FAIL Known Test Event After merge, automation can invoke the real cloud function with a known event. This verifies packaging, deployment, runtime configuration, and invocation. 20 CSC 5100 • Software Engineering 14
  16. Development → GitHub → AWS IDE Implement Lambda JUnit /

    pytest mvn test / pytest GitHub Branch + commit Push + Pull Request GitHub Actions AWS Run tests automatically Build deployment artifact Deploy Lambda API Gateway invokes it. 1 • Develop & unit test 2 • Review & verify 3 • Deploy & integrate Fast feedback. No web server. No AWS credentials needed. PR is the gate. Actions repeat the tests in a clean environment. After merge, the workflow deploys. Then test the real HTTP endpoint. Your IDE does not need to deploy directly to AWS. Deployment flow through GitHub Actions after the PR is accepted. 21 CSC 5100 • Software Engineering 24
  17. Our classroom model Student GitHub Branch Pull Request Instructor Merge

    GitHub Actions AWS Lambda You do NOT need individual AWS accounts for this lab. AWS credentials stay with the deployment workflow—not in the developer code. AWS is centralized; development stays in the workflow you already know. 23 CSC 5100 • Software Engineering 8
  18. Repository structure CSC5100-starter-files/ ├── pom.xml ├── src/main/java/... • Lambda code

    is simply another deliverable in the project. • Story describes the cloud behavior ├── src/test/java/... └── lambda/ └── temperature/ ├── pom.xml • Tasks divide implementation/testing work ├── src/main/java/ • PR is reviewed exactly as before │ └── .../TemperatureHandler.java └── src/test/java/ └── .../TemperatureHandlerTest.java • Merge is the deployment gate • Same Git workflow. New execution environment. 24 CSC 5100 • Software Engineering 9
  19. CSC 5100 Modern Software Engineering Javier Gonzalez-Sanchez, Ph.D. [email protected] Fall

    2026 Copyright. These slides may be used only as study material for CSC 5100 within the California State University system. They may not be distributed or used for any other purpose.