serverless-plugin-simulate
serverless-plugin-simulate copied to clipboard
Support explicitly specified artifacts e.g. fat JARs
What did you implement:
Fixes #89.
How did you implement it:
We check whether the serverless.variables.service.package.artifact
variable exists. If it does, it gets attached to every function object. When a function is invoked, if the artifact variable is set, the artifact is unpacked with the unzip
shell command to a temporary directory .sls-simulate-unzipped
. That directory is mounted into the docker container at /var/task
. Otherwise the project root is mounted there.
How can we verify it:
You can pick any JVM Serverless project, whichever is easiest for you. Here's instructions for Scala/SBT
-
sls create -t aws-scala-sbt -p foo
- Replace
serverless.yml
with this:
service: scala-template
provider:
name: aws
runtime: java8
package:
artifact: target/scala-2.12/hello.jar
functions:
hello:
handler: hello.ApiGatewayHandler
events:
- http:
path: hello
method: get
plugins:
- serverless-plugin-simulate
-
sbt assembly
- You'll need to have SBT installed -
sls simulate apigateway
- in another terminal
curl http://localhost:3000/hello
You should see this:
Serverless: Creating event
Serverless: Invoking hello
Serverless: Invoking function hello.ApiGatewayHandler
WARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.
START RequestId: 347d188f-702f-4838-82c5-620ad9367f17 Version: $LATEST
END RequestId: 347d188f-702f-4838-82c5-620ad9367f17
REPORT RequestId: 347d188f-702f-4838-82c5-620ad9367f17 Duration: 230.17 ms Billed Duration: 300 ms Memory Size: 1024 MB Max Memory Used: 24 MB
{"statusCode":200,"body":"Go Serverless v1.0! Your function executed successfully!","headers":{"x-custom-response-header":"my custom response header value"},"base64Encoded":true}
Serverless: Mapping response
GET /hello 200 1125.335 ms - 56
Without this PR you'll get the error from #89.
Todos:
- [x] Write tests
- [x] Write documentation - bugfixes don't need documentation
- [x] Fix linting errors
- [x] Provide verification config/commands/resources
- [x] Change ready for review message below
Is this ready for review?: YES