Swift implementation of AWS Lambda Runtime
See the codeDevelop and deploy AWS Lambda functions written in Swift.
The Swift AWS Lambda Runtime is an implementation of the AWS Lambda Runtime API. It uses an embedded asynchronous HTTP client based on SwiftNIO and provides a layered API for building a range of Lambda functions, from simple closures to complex, performance-sensitive event handlers.
The full documentation lives on the Swift Package Index.
New to Swift on Lambda? Start with the step-by-step tutorial. It walks you through writing, building, testing, and deploying your first function.
The documentation also covers:
You need the Swift 6.x toolchain, Docker (or Apple container) to build for Amazon Linux, and the AWS CLI configured with aws configure. On macOS, use macOS 15 (Sequoia) or later.
mkdir MyLambda && cd MyLambda
swift package init --type executable --name MyLambda
swift package add-dependency https://github.com/awslabs/swift-aws-lambda-runtime.git --from 3.0.0
swift package add-target-dependency AWSLambdaRuntime MyLambda --package swift-aws-lambda-runtime
Sources/MyLambda/MyLambda.swift.swift package lambda-init --allow-writing-to-package-directory
The generated function receives a JSON event and returns a JSON response.
import AWSLambdaRuntime
struct HelloRequest: Decodable {
let name: String
let age: Int
}
struct HelloResponse: Encodable {
let greetings: String
}
let runtime = LambdaRuntime {
(event: HelloRequest, context: LambdaContext) in
HelloResponse(
greetings: "Hello \(event.name). You look \(event.age > 30 ? "younger" : "older") than your age."
)
}
try await runtime.run()
swift run starts a local server on port 7000.swift run &
curl --header "Content-Type: application/json" \
--data '{"name":"World","age":30}' \
http://127.0.0.1:7000/invoke
swift package --allow-network-connections docker lambda-build
swift package --allow-network-connections all:443 lambda-deploy
aws lambda invoke \
--function-name MyLambda \
--payload $(echo '{"name":"World","age":30}' | base64) \
/dev/stdout
For the full walkthrough, see the getting started guide and the tutorial.
The Examples directory contains complete, runnable functions covering JSON, API Gateway, streaming, background tasks, Service Lifecycle with PostgreSQL, and more.
The Swift runtime client is incubating as part of the Swift Server Workgroup incubation process. It is an experimental package, subject to change, and intended only for evaluation purposes.
646 followers · starred May 2020
26 followers · starred Jun 2023
261 followers · starred May 2020
180 followers · starred May 2020
Swift implementation of AWS Lambda Runtime
See the codeDevelop and deploy AWS Lambda functions written in Swift.
The Swift AWS Lambda Runtime is an implementation of the AWS Lambda Runtime API. It uses an embedded asynchronous HTTP client based on SwiftNIO and provides a layered API for building a range of Lambda functions, from simple closures to complex, performance-sensitive event handlers.
The full documentation lives on the Swift Package Index.
New to Swift on Lambda? Start with the step-by-step tutorial. It walks you through writing, building, testing, and deploying your first function.
The documentation also covers:
You need the Swift 6.x toolchain, Docker (or Apple container) to build for Amazon Linux, and the AWS CLI configured with aws configure. On macOS, use macOS 15 (Sequoia) or later.
mkdir MyLambda && cd MyLambda
swift package init --type executable --name MyLambda
swift package add-dependency https://github.com/awslabs/swift-aws-lambda-runtime.git --from 3.0.0
swift package add-target-dependency AWSLambdaRuntime MyLambda --package swift-aws-lambda-runtime
Sources/MyLambda/MyLambda.swift.swift package lambda-init --allow-writing-to-package-directory
The generated function receives a JSON event and returns a JSON response.
import AWSLambdaRuntime
struct HelloRequest: Decodable {
let name: String
let age: Int
}
struct HelloResponse: Encodable {
let greetings: String
}
let runtime = LambdaRuntime {
(event: HelloRequest, context: LambdaContext) in
HelloResponse(
greetings: "Hello \(event.name). You look \(event.age > 30 ? "younger" : "older") than your age."
)
}
try await runtime.run()
swift run starts a local server on port 7000.swift run &
curl --header "Content-Type: application/json" \
--data '{"name":"World","age":30}' \
http://127.0.0.1:7000/invoke
swift package --allow-network-connections docker lambda-build
swift package --allow-network-connections all:443 lambda-deploy
aws lambda invoke \
--function-name MyLambda \
--payload $(echo '{"name":"World","age":30}' | base64) \
/dev/stdout
For the full walkthrough, see the getting started guide and the tutorial.
The Examples directory contains complete, runnable functions covering JSON, API Gateway, streaming, background tasks, Service Lifecycle with PostgreSQL, and more.
The Swift runtime client is incubating as part of the Swift Server Workgroup incubation process. It is an experimental package, subject to change, and intended only for evaluation purposes.
646 followers · starred May 2020
26 followers · starred Jun 2023
261 followers · starred May 2020
180 followers · starred May 2020