This project is swift sample for AWS Lambda connect with sqlite DB.
see Swift-AWS-SQLite
- Clone this project and run it on Xcode 12
- Verify with curl
$ curl --header "Content-Type: application/json" \
--request POST \
--data '{"id": 1}' \
http://localhost:7000/invoke
it will response with
{
"account":{
"ID":1,
"dateOfBirth":"10-12-1991",
"Name":"Hanif",
"email":"[email protected]"
},
"message":"success"
}
- Upload accountData.db into your S3
Sources/AccountServiceAWS/DB/accountData.db
- Change S3 bucket name and AWS Client on SharedResource.swift with your S3 account key
static public let s3BucketName = "your bucket name"
static public let awsClient = AWSClient(
credentialProvider: .static(accessKeyId: "xxxx", secretAccessKey: "xxxxx"),
httpClientProvider: .createNew)
- Go to project directory on terminal
- Run docker command
$ docker run \
--rm \
--volume "$(pwd)/:/src" \
--workdir "/src/" \
swift:5.3.1-amazonlinux2 \
/bin/bash -c "yum -y install sqlite-devel && swift build --product AccountServiceAWS -c release -Xswiftc -static-stdlib"
- Run the script for creating lambda.zip
$ ./scripts/package.sh AccountServiceAWS
- Result will be available on :
.build/lambda/AccountServiceAWS/lambda.zip
- Upload your lambda.zip to S3 bucket
- when on Lambda use that S3 link to compile the function.