AWS Swift Lambda Template
The goal of this package is to have a simple template for AWS Lambda on Swift.
DBService
DBService
is a CRUD
implementation wrapper for AWSDynamoDB
.
The item
representation from the data base should confirm DynamoDBConvertable
protocol:
protocol DynamoDBConvertable {
static var primaryKeyField: String { get }
var primaryKeyValue: String { get }
var dbItem: [String: DynamoDB.AttributeValue] { get }
init(withDBItem dbItem: [String: DynamoDB.AttributeValue]) throws
}
primaryKeyField
is a name ofprimaryKey
inDynamoDB
tableprimaryKeyValue
is a value ofprimaryKey
initem
objectdbItem
is a representation of your object forDynamoDB
Handlers
You will find two test handlers in the package:
ApiGatewayHandler
implements aCRUD
functionality for\items
test resource. For each endpoint it calls aDBService
function respectively.CloudwatchScheduleHandler
is a simpleCloudwatch.Scheduled
event implementation. It will handle any scheduled event fromCloudWatch
and create a newitem
inDynamoDB
usingDBService
.
Run Locally on Mac OS
To run lambda locally on Mac OS you need to add LOCAL_LAMBDA_SERVER_ENABLED
with value true
as an Environment Variable
- Open
Edit Scheme...
menu - In
Run
section addLOCAL_LAMBDA_SERVER_ENABLED
variable with valuetrue
Build for AWS
- Execute
docker build
command
$ docker build -t aws-swift-lambda-template-image .
- Execute
docker run
command
$ docker run \
--rm \
--volume "$(pwd)/:/src" \
--workdir "/src/" \
aws-swift-lambda-template-image \
swift build --product aws-swift-lambda-template -c release
- Execute
docker run
command
$ docker run \
--rm \
--volume "$(pwd)/:/src" \
--workdir "/src/" \
aws-swift-lambda-template-image \
scripts/package.sh aws-swift-lambda-template
- Take a
lambda.zip
from.build/lambda/aws-swift-lambda-template
folder and upload toAWS
🎉