Skip to content

Conversation

@sebsto
Copy link
Collaborator

@sebsto sebsto commented Oct 30, 2025

This PR adds a new example demonstrating how to build a Lambda function that handles requests from multiple sources (Application Load Balancer and API Gateway V2) using a single handler.

What's New

New Example: Examples/MultiSourceAPI

A Lambda function that:

  • Implements StreamingLambdaHandler to accept raw ByteBuffer events
  • Dynamically decodes events as either ALBTargetGroupRequest or APIGatewayV2Request
  • Returns appropriate responses based on the detected event source
  • Demonstrates handling multiple AWS service integrations with a single function

Key Features

  • Type-safe event detection: Uses Swift's Decodable to identify the event source at runtime
  • Streaming response: Implements StreamingLambdaHandler for efficient response handling
  • Complete deployment: Includes SAM template with both ALB and API Gateway V2 infrastructure
  • Production-ready: Full VPC setup with subnets, security groups, and load balancer configuration

Files Added

  • Examples/MultiSourceAPI/Sources/main.swift - Lambda handler implementation
  • Examples/MultiSourceAPI/Package.swift - Swift package configuration
  • Examples/MultiSourceAPI/template.yaml - SAM deployment template with ALB and API Gateway V2
  • Examples/MultiSourceAPI/README.md - Documentation with build, deploy, and test instructions
  • Updated CI to include the new example

Use Case

This pattern is useful when you want to:

  • Expose the same Lambda function through multiple AWS services
  • Reduce code duplication by handling similar requests from different sources
  • Maintain a single codebase for multi-channel APIs

@sebsto sebsto self-assigned this Oct 30, 2025
@sebsto sebsto added the 🆕 semver/minor Adds new public API. label Oct 30, 2025
@sebsto sebsto requested a review from Copilot October 30, 2025 10:29
@sebsto sebsto marked this pull request as ready for review October 30, 2025 10:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new MultiSourceAPI example that demonstrates a Lambda function capable of handling requests from both Application Load Balancer (ALB) and API Gateway V2. The handler receives raw ByteBuffer events and uses pattern matching with type-safe decoding to determine the event source and return the appropriate response.

Key changes:

  • Implements a StreamingLambdaHandler that decodes incoming events as either ALBTargetGroupRequest or APIGatewayV2Request
  • Includes complete AWS infrastructure setup with VPC, subnets, ALB, and API Gateway V2
  • Adds the new example to the CI workflow

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
Examples/MultiSourceAPI/Sources/main.swift Core Lambda handler implementing multi-source event processing logic
Examples/MultiSourceAPI/Package.swift Swift package manifest defining dependencies and build configuration
Examples/MultiSourceAPI/template.yaml SAM template defining AWS infrastructure including ALB and API Gateway
Examples/MultiSourceAPI/samconfig.toml SAM CLI configuration for deployment
Examples/MultiSourceAPI/README.md Documentation explaining usage and deployment
Examples/MultiSourceAPI/.gitignore Standard Swift project ignore patterns
Examples/MultiSourceAPI/.aws-sam/build/template.yaml Generated SAM build artifact
Examples/MultiSourceAPI/.aws-sam/build.toml Generated SAM build metadata
.github/workflows/pull_request.yml Updated CI workflow to include new example

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sebsto sebsto requested a review from jbelkins October 30, 2025 10:32
@sebsto sebsto merged commit 97583a7 into main Nov 2, 2025
35 of 119 checks passed
@sebsto sebsto deleted the sebsto/multisource branch November 2, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants