Skip to content

Commit d22906c

Browse files
committed
feat(runtime,makefiles): Add workable lambda for both runtimes
Still lacks custom logger
1 parent 0172ffd commit d22906c

File tree

8 files changed

+207
-70
lines changed

8 files changed

+207
-70
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/target
2+
packaged.yml
3+
native-packaged.yml
4+
*.zip
25
bootstrap
36
/classes
47
/checkouts

examples/hello-lambda/Makefile

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ SHELL := /bin/bash
22
GREEN='\033[0;32m'
33
YELLOW='\033[1;33m'
44
NC='\033[0m'
5-
DEFAULT_NATIVE_PARAMETERS="ParameterKey=Runtime,ParameterValue=provided ParameterKey=CodeUri,ParameterValue=."
65

76
.PHONY: install-holy-lambda native-dry-run compile dry-run native-compile
7+
BUCKET_NAME=holy-lambda--hello-lambda
8+
STACK_NAME=holy-lambda--hello-lambda
9+
APP_REGION=eu-central-1
10+
11+
make-bucket:
12+
@aws s3 mb s3://$(BUCKET_NAME)
13+
14+
destroy-bucket:
15+
@aws s3 rb s3://$(BUCKET_NAME) --force --region $(APP_REGION)
816

917
install-holy-lambda:
1018
@bash -c "cd ../../ && lein install"
@@ -17,8 +25,23 @@ dry-api:
1725

1826
native-compile:
1927
@fnative "-jar target/hello-lambda.jar --report-unsupported-elements-at-runtime --no-fallback --enable-url-protocols=http,https --no-server -J-Xmx3G -J-Xms3G"
28+
@cp -rf hello-lambda bootstrap
29+
@zip latest bootstrap
2030

2131
native-dry-api:
22-
@rm -Rf bootstrap
23-
@mv hello-lambda bootstrap
24-
sam local start-api --parameter-overrides='$(DEFAULT_NATIVE_PARAMETERS)'
32+
@sam local start-api --template ./native-template.yml
33+
34+
pack:
35+
@sam package --template-file ./template.yml --output-template-file packaged.yaml --s3-bucket $(BUCKET_NAME) --s3-prefix "hello-lambda-latest"
36+
37+
deploy:
38+
@sam deploy --template-file ./packaged.yaml --stack-name $(STACK_NAME) --capabilities CAPABILITY_IAM --region $(APP_REGION)
39+
40+
native-pack:
41+
@sam package --template-file ./native-template.yml --output-template-file native-packaged.yaml --s3-bucket $(BUCKET_NAME) --s3-prefix "hello-lambda-latest"
42+
43+
native-deploy:
44+
@sam deploy --template-file ./native-packaged.yaml --stack-name $(STACK_NAME) --capabilities CAPABILITY_IAM --region $(APP_REGION)
45+
46+
native-destroy:
47+
@aws cloudformation delete-stack --stack-name $(STACK_NAME) --region $(APP_REGION)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
Description: 'Example basic lambda using `holy-lambda` micro library
4+
5+
'
6+
Parameters:
7+
Runtime:
8+
Type: String
9+
Default: provided
10+
Timeout:
11+
Type: Number
12+
Default: 40
13+
MemorySize:
14+
Type: Number
15+
Default: 2000
16+
CodeUri:
17+
Type: String
18+
Default: latest.zip
19+
Globals:
20+
Function:
21+
Runtime:
22+
Ref: Runtime
23+
Timeout:
24+
Ref: Timeout
25+
MemorySize:
26+
Ref: MemorySize
27+
CodeUri:
28+
Ref: CodeUri
29+
Resources:
30+
GetOrderFunction:
31+
Type: AWS::Serverless::Function
32+
Properties:
33+
Handler: hello-lambda.core.HelloLambda
34+
FunctionName: HelloLambdaFunction
35+
Events:
36+
HelloLambda:
37+
Type: Api
38+
Properties:
39+
Path: /
40+
Method: get
41+
CodeUri: s3://holy-lambda--hello-lambda/hello-lambda-latest/42c3700297f855bc99543ad80034ce5d
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
Description: >
4+
Example basic lambda using `holy-lambda` micro library
5+
6+
Parameters:
7+
Runtime:
8+
Type: String
9+
Default: provided
10+
Timeout:
11+
Type: Number
12+
Default: 40
13+
MemorySize:
14+
Type: Number
15+
Default: 2000
16+
CodeUri:
17+
Type: String
18+
Default: latest.zip
19+
20+
Globals:
21+
Function:
22+
Runtime: !Ref Runtime
23+
Timeout: !Ref Timeout
24+
MemorySize: !Ref MemorySize
25+
CodeUri: !Ref CodeUri
26+
27+
Resources:
28+
GetOrderFunction:
29+
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
30+
Properties:
31+
Handler: hello-lambda.core.HelloLambda
32+
FunctionName: HelloLambdaFunction
33+
Events:
34+
HelloLambda:
35+
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
36+
Properties:
37+
Path: /
38+
Method: get

examples/hello-lambda/packaged.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
Description: 'Example basic lambda using `holy-lambda` micro library
4+
5+
'
6+
Parameters:
7+
Runtime:
8+
Type: String
9+
Default: java8
10+
Timeout:
11+
Type: Number
12+
Default: 40
13+
MemorySize:
14+
Type: Number
15+
Default: 2000
16+
CodeUri:
17+
Type: String
18+
Default: target/hello-lambda.jar
19+
Globals:
20+
Function:
21+
Runtime:
22+
Ref: Runtime
23+
Timeout:
24+
Ref: Timeout
25+
MemorySize:
26+
Ref: MemorySize
27+
CodeUri:
28+
Ref: CodeUri
29+
Resources:
30+
GetOrderFunction:
31+
Type: AWS::Serverless::Function
32+
Properties:
33+
Handler: hello-lambda.core.HelloLambda
34+
FunctionName: HelloLambdaFunction
35+
Events:
36+
HelloLambda:
37+
Type: Api
38+
Properties:
39+
Path: /
40+
Method: get
41+
CodeUri: s3://holy-lambda--hello-lambda/hello-lambda-latest/353cd8a931c84b187ce9790e579c265b

examples/hello-lambda/src/hello_lambda/core.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
(h/deflambda HelloLambda
77
[event context]
88
{:statusCode 200
9-
:body "Hello"
9+
:body {:message "Hello"
10+
"it's" "me"
11+
:you "looking"
12+
:for true}
1013
:isBase64Encoded false
11-
:headers {"content-type" "text/html"}}
12-
)
14+
:headers {"Content-Type" "application/json"}})
1315

1416
(h/gen-main [#'HelloLambda])

examples/hello-lambda/template.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ Parameters:
88
Type: String
99
Default: java8
1010
Timeout:
11-
Type: Integer
11+
Type: Number
1212
Default: 40
1313
MemorySize:
14-
Type: Integer
14+
Type: Number
1515
Default: 2000
1616
CodeUri:
1717
Type: String

0 commit comments

Comments
 (0)