Skip to content

Commit 8102fa1

Browse files
committed
Test demo function with sam local invoke on commit.
1 parent 3622e02 commit 8102fa1

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

.github/workflows/on-push.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ jobs:
1717
run: ./gradlew build
1818
- name: Build demo with Gradle
1919
run: ./gradlew :demo:packageLambda
20+
- name: Invoke demo function locally
21+
run: ./gradlew :demo:localInvoke

demo/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,22 @@ task buildDocker(type: Exec) {
4141
dependsOn classes
4242
commandLine './buildDocker.sh'
4343
}
44+
45+
task localInvoke {
46+
doLast {
47+
def file = new File(getTemporaryDir(), "out.json")
48+
def event = '{"message": "hello world"}'
49+
def command = "echo '${event}' | sam local invoke --event - > ${file}"
50+
println "Running command: ${command}"
51+
exec {
52+
executable 'bash'
53+
args '-c', command
54+
}
55+
def expectedOutput = '{"message":"Received message: hello world"}'
56+
def actualOutput = file.text.trim()
57+
println actualOutput
58+
if (!expectedOutput.equals(actualOutput)) {
59+
throw new RuntimeException("Expected output:\n\t${expectedOutput}\nActual output:\n\t${actualOutput}")
60+
}
61+
}
62+
}

demo/template.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Transform: AWS::Serverless-2016-10-31
2+
Resources:
3+
DemoFunction:
4+
Type: AWS::Serverless::Function
5+
Properties:
6+
CodeUri: build/distributions/demo.zip # generated by ../gradlew :demo:packageLambda
7+
Handler: "" # handler is built into the runtime, value is not used
8+
Runtime: provided

0 commit comments

Comments
 (0)