Deploy HTTP Services Written in Swift to AWS in Seconds
- by admin
Recently, Apple announced the Swift AWS Lambda Runtime. It’s now possible to write self-contained functions that run on AWS using the same Swift you use for iOS development. This not only lets you reuse the knowledge you already have of Swift, but also share code between the server and client.
However, everything is still a little bit complicated to set up. To help you get started faster, I built a starting point for writing an HTTP service in Swift, which does everything you need in a single script.
Swift Lambda contains configuration files and scripts to fully automate deploying to AWS in a matter of seconds using the Serverless Framework. It’s based on samples and documentation from swift-server/swift-aws-lambda-runtime.
- Clone the repository: https://github.com/GetStream/swift-lambda
- Install Docker
- Install the Serverless Framework
- Configure the AWS Credentials
- Write your code in
- Deploy by running
- Open the output URL in your browser:
There is some code already present in the
Sources/Lambda/main.swift file. It simply outputs "Hello, world!" in plain text.
If you want to output some HTML, just set the
Content-Type header to
For more information on the available settings and methods, refer to the Swift AWS Lambda Runtime README.
Configuring the Endpoint
To change some characteristics of your HTTP endpoint, such as the method expected, you should modify the
serverless.yml file. For more information on the available parameters, refer to the Serverless.yml Reference