Building Swift Serverless REST API with AWS Lambda & DynamoDB
--
Last month, The Swift Core Team & Swift Server Work Group had announced the availability of Swift AWS Lambda Runtime as well as support of Swift on Amazon Linux 2 OS. With both of this announcement, we finally have some official support to run Swift on AWS Lambda environment.
Swift has many advantages such as low memory footprint, high performance, and quick start time. The Swift AWS Lambda runtime also uses SwiftNIO
to provide high performance non blocking networking engine for us to run asynchronous event driven code.
The runtime itself provides built-in support for many Lambda supported events such as HTTP request event from API Gateway, S3 object storage event, Simple Notification Service, and Simple Queue Service.
What We Will Build
In this tutorial, we’ll build a simple Swift Serverless REST API endpoints to create, update, delete, and retrieve list of todo. Here are the topics we’ll learn:
- Swift Lambda Runtime to handle API Gateway request event.
- Swift AWS DynamoDB SDK to persist the todo data in the Cloud.
- SwiftNIO to handle asynchronous event processing in network using EventLoopFuture.
- Docker to build and package the Swift binary ready for AWS Lambda Custom provided runtime.
- Serverless Framework to provision and deploy to AWS Lambda with IAM Role.
You can download the completed project Source from the GitHub repository. I have provided the backend
and iOS client
app under one repository. Please follow the instruction on the README
file to build.