Skip to content

Commit 1a67128

Browse files
author
Jan Kammerath
committed
base files for the build process
0 parents  commit 1a67128

File tree

6 files changed

+127
-0
lines changed

6 files changed

+127
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.build
2+
bootstrap
3+
*.resolved

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build:
2+
docker run --rm --platform linux/arm64 -v "$(PWD):/src" -w /src swift:5.9.1-amazonlinux2 /bin/bash \
3+
-c "swift build --product ServerlessSwift -c release -Xswiftc -static-stdlib; mv .build/release/ServerlessSwift bootstrap"

Package.swift

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// swift-tools-version: 5.9.1
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "ServerlessSwift",
6+
products: [
7+
.executable(name: "ServerlessSwift", targets: ["ServerlessSwift"])
8+
],
9+
dependencies: [
10+
.package(url: "https://github.com/vapor/vapor.git", .upToNextMajor(from: "4.0.0")),
11+
.package(url: "https://github.com/vapor-community/vapor-aws-lambda-runtime", .upToNextMajor(from: "0.4.0"))
12+
],
13+
targets: [
14+
.executableTarget(
15+
name: "ServerlessSwift",
16+
dependencies: [
17+
.product(name: "Vapor", package: "vapor"),
18+
.product(name: "VaporAWSLambdaRuntime", package: "vapor-aws-lambda-runtime")
19+
],
20+
path: ".",
21+
exclude: ["Makefile", "template.yaml", "sam-launch.sh"]
22+
),
23+
]
24+
)

sam-launch.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
sam local start-api --template template.yaml

src/main.swift

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Vapor
2+
import VaporAWSLambdaRuntime
3+
4+
let app = Application()
5+
6+
struct Pong: Content {
7+
let pong: String
8+
}
9+
10+
app.get("ping") { (_) -> Pong in
11+
Pong(pong: "hello")
12+
}
13+
14+
app.servers.use(.lambda)
15+
16+
try app.run()

template.yaml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
Description: Serverless Swift API
4+
5+
Resources:
6+
RestApi:
7+
Type: AWS::Serverless::Api
8+
Properties:
9+
StageName: Prod
10+
11+
ApiFunction:
12+
Type: AWS::Serverless::Function
13+
Properties:
14+
Handler: bootstrap
15+
Runtime: provided.al2
16+
CodeUri: .
17+
MemorySize: 128
18+
Timeout: 30
19+
Architectures:
20+
- arm64
21+
Events:
22+
RootEvent:
23+
Type: Api
24+
Properties:
25+
RestApiId: !Ref RestApi
26+
Path: /
27+
Method: any
28+
Auth:
29+
ApiKeyRequired: true
30+
ProxyEvent:
31+
Type: Api
32+
Properties:
33+
RestApiId: !Ref RestApi
34+
Path: /{proxy+}
35+
Method: any
36+
Auth:
37+
ApiKeyRequired: true
38+
39+
ApiKey:
40+
Type: AWS::ApiGateway::ApiKey
41+
DependsOn:
42+
- RestApi
43+
- RestApiProdStage
44+
- ApiFunction
45+
Properties:
46+
Name: !Join ["", [{"Ref": "AWS::StackName"}, "-apikey-", !Select [2, !Split ['/', !Ref AWS::StackId]]]]
47+
Description: "API Key"
48+
Enabled: true
49+
StageKeys:
50+
- RestApiId: !Ref RestApi
51+
StageName: Prod
52+
53+
ApiUsagePlan:
54+
Type: AWS::ApiGateway::UsagePlan
55+
DependsOn:
56+
- RestApi
57+
- RestApiProdStage
58+
- ApiFunction
59+
Properties:
60+
ApiStages:
61+
- ApiId: !Ref RestApi
62+
Stage: Prod
63+
Description: !Join [" ", [{"Ref": "AWS::StackName"}, "usage plan"]]
64+
Quota:
65+
Limit: 1000
66+
Period: DAY
67+
UsagePlanName: !Join ["", [{"Ref": "AWS::StackName"}, "-usage-plan"]]
68+
69+
ApiUsagePlanKey:
70+
Type: AWS::ApiGateway::UsagePlanKey
71+
DependsOn:
72+
- RestApi
73+
- RestApiProdStage
74+
- ApiKey
75+
- ApiUsagePlan
76+
Properties:
77+
KeyId: !Ref ApiKey
78+
KeyType: API_KEY
79+
UsagePlanId: !Ref ApiUsagePlan

0 commit comments

Comments
 (0)