-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
99 lines (85 loc) · 3.76 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
plugins {
id 'scala'
id 'com.github.johnrengelman.shadow' version '2.0.0'
id 'jp.classmethod.aws.lambda' version '0.35'
}
import com.amazonaws.services.lambda.model.Runtime;
import com.amazonaws.services.lambda.model.InvocationType;
import jp.classmethod.aws.gradle.lambda.AWSLambdaDeleteFunctionTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaInvokeTask;
import jp.classmethod.aws.gradle.lambda.AWSLambdaMigrateFunctionTask;
version = '0.1-SNAPSHOT'
ext.functionName = 'dot-product'
ext.pojoFunctionName = ext.functionName + "-pojo"
ext.streamFunctionName = ext.functionName + "-stream"
ext.role = "arn:aws:iam::${aws.accountId}:role/lambda"
ext.timeout = 8 // in seconds. it might be slow the first time :(
ext.memorySize = 512 // in MB.
ext.runtime = Runtime.Java8
ext.payload = file("src/test/resources/input.json") // sample input data, 2 serialized vectors in 3-space
ext.invocationType = InvocationType.RequestResponse
ext.artifactPath = shadowJar.archivePath // path to the shadowjar. we'll upload this jar to lambda when creating functions
repositories {
jcenter()
}
dependencies {
compile group: 'com.amazonaws', name: 'aws-java-sdk-lambda', version: '1.11.141'
compile group: 'com.amazonaws', name: 'aws-lambda-java-core', version: '1.1.0'
compile group: 'org.json4s', name: 'json4s-jackson_2.12', version: '3.5.2'
compile group: 'org.scala-lang', name: 'scala-library', version: '2.12.2'
compile group: 'org.tinylog', name: 'tinylog', version: '1.2'
testCompile group: 'org.scalatest', name: 'scalatest_2.12', version: '3.0.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
shadowJar {
version = project.version
}
// uploads our shadowjar artifact to lambda.
// your ~/.aws/credentials file should be correctly populated with key and secret
task uploadPojoLambda(type: AWSLambdaMigrateFunctionTask, dependsOn: shadowJar) {
functionName = project.pojoFunctionName
role = project.role
runtime = project.runtime
timeout = project.timeout
memorySize = project.memorySize
zipFile = project.artifactPath
handler = 'com.workday.warp.handlers.PojoDotProductHandler::handleRequest'
}
// deletes the lambda function associated with our pojo request type
task deletePojoLambda(type: AWSLambdaDeleteFunctionTask) {
functionName = project.pojoFunctionName
}
// invokes the lambda function associated with our pojo request type
task invokePojoLambda(type: AWSLambdaInvokeTask) {
functionName = project.pojoFunctionName
invocationType = project.invocationType
payload = project.payload
doLast {
println "Lambda function (using pojo java-bean POJO deserialization) results: "
println " status code: " + invokeResult.statusCode
println " payload: " + new String(invokeResult.payload.array(), "UTF-8")
}
}
// similar tasks for immutable version using json4s deserialization.
task uploadStreamLambda(type: AWSLambdaMigrateFunctionTask, dependsOn: shadowJar) {
functionName = project.streamFunctionName
role = project.role
runtime = project.runtime
timeout = project.timeout
memorySize = project.memorySize
zipFile = project.artifactPath
handler = 'com.workday.warp.handlers.StreamDotProductHandler::handleRequest'
}
task deleteStreamLambda(type: AWSLambdaDeleteFunctionTask) {
functionName = project.streamFunctionName
}
task invokeStreamLambda(type: AWSLambdaInvokeTask) {
functionName = project.streamFunctionName
invocationType = project.invocationType
payload = project.payload
doLast {
println "Lambda function (using stream json4s deserialization with immutable case classes) results: "
println " status code: " + invokeResult.statusCode
println " payload: " + new String(invokeResult.payload.array(), "UTF-8")
}
}