This package demostrates how to write a Scalable HTML form server with the Serverless stack by using only Swift as development language.
The example is a very basic HTML web form styled with bootstrap and rendered by Swift
.
It doesn't contain any JavaScript as in this example I wanted to show that sometime is not needed 😁.
The form posts different application/x-www-form-urlencoded
forms to perform basic CRUD actions.
The architecture is based on the classical AWS Serverless stack: APIGateway, Lambda and DynamoDB.
APIGateway
: acts as aproxy
for theLambda
and exposing it to the internet.Lambda
: is the computational layer.DynamoDB
: is the AWSNoSQL
database
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 actions send from the web form are converted to shows different pages.
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
- Plot: Renders the HTML
- Boostrap: CSS for HTML pages. (JavaScript - Disabled)
- 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 --version
the 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