Skip to content

Latest commit

 

History

History
61 lines (49 loc) · 2.61 KB

File metadata and controls

61 lines (49 loc) · 2.61 KB

Swift Lambda example with SAM

This projects builds two Lambda functions built with Swift. Squared is a simple Lambda that returns the squared value of a number. SwiftApi is a simple Lambda function that triggers from an HTTP API.

You will not need Swift installed locally as we will use an Amazon Linux container to build the functions.

Prerequisites

  1. Docker
  2. SAM CLI >= 0.52.0

Setup - Create docker image for compiling

docker build -f Dockerfile . -t builder

Build options

  1. sam build from the root directory will compile each function and prepare for testing and deployment. Docs
  2. make build-FunctionName will build JUST the single Lambda function.

Test Local

Run these commands from the root of the project.

SwiftApi:

sam local start-api

or

sam local invoke SwiftApi -e events/api-event.json

Squared

sam local invoke Squared -e events/squared-event.json

Deployment

Use sam deploy from the root of the project. Docs

Credit

I used both these amazing resources to figure this out.

  1. https://fabianfett.de/getting-started-with-swift-aws-lambda-runtime
  2. https://github.com/swift-server/swift-aws-lambda-runtime

Note: I am not an amazing makefile expert or Swift developer. Any feedback on my process is wanted and welcome