This package demostrates how to write a Scalable REST API with the Serverless stack by using only Swift as development language.
The example shows how to build a Rest API based on a Product swift class.
public struct Product: Codable { public let sku: String public let name: String public let description: String public var createdAt: String? public var updatedAt: String? }- /Product -> GET -> POST -> PUT - /Product/{sku} -> DELETE -> GET JSON body for PUT and POST
{ "sku": "3", "name": "Book", "description": "Book 3" }The architecture is based on the classical AWS Serverless stack: APIGateway, Lambda and DynamoDB.
APIGateway: acts as aproxyfor theLambdaand exposing it to the internet.Lambda: is the computational layer.DynamoDB: is the AWSNoSQLdatabase
Advantages:
- Pay per use
- No fixed costs
- Auto-Scaling
- DevOps
The application uses Swift-Sprinter as AWS Custom Lambda Runtime and acts as a presentation layer of the DynamoDB content via Web.
The following frameworks are used:
- aws-lambda-swift-sprinter-nio-plugin: Implements the AWS Custom Runtime usin Swift NIO.
- aws-sdk-swift: Interacts with DynamoDB
- Install Docker
- Install Serverless Framework
- Ensure your AWS Account has the right credentials to deploy a Serverless stack.
- Clone this repository. From the command line type:
git clone https://github.com/swift-sprinter/aws-serverless-swift-sprinter-web-template cd aws-serverless-swift-sprinter-web-template- Ensure you can run
make:
make --versionthe Makefile was developed with this version:
GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for i386-apple-darwin11.3.0 Use the following command to build the code before using the serverless commands:
./build.sh Deploy the full solution to your AWS using Serverless:
./deploy.sh After the deployment is completed, the URL of the website is provided by the Serverless framework.
Rebuild the code and update the Lambda to your AWS using Serverless:
./update.sh To remove the deployment use:
serverless remove