Skip to content

Commit 5a35b67

Browse files
committed
allow specifying path for mountCode, to point to a relative Lambda mount path
1 parent f8b82c7 commit 5a35b67

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ custom:
5050
- my_custom_network
5151
lambda:
5252
# Enable this flag to improve performance
53-
mountCode: True
53+
mountCode: true # specify either "true", or a relative path to the root Lambda mount path
5454
docker:
5555
# Enable this flag to run "docker ..." commands as sudo
5656
sudo: False
@@ -67,10 +67,13 @@ Note the `stages` attribute in the config above. The `serverless-localstack` plu
6767

6868
### Mounting Lambda code for better performance
6969

70-
Note that the `localstack.lambda.mountCode` flag above will mount the local directory
71-
into the Docker container that runs the Lambda code in LocalStack. If you remove this
72-
flag, your Lambda code is deployed in the traditional way which is more in line with
73-
how things work in AWS, but also comes with a performance penalty: packaging the code,
70+
Note that the `localstack.lambda.mountCode` flag above will mount the local directory into
71+
the Docker container that runs the Lambda code in LocalStack. You can either specify the boolean
72+
value `true` (to mount the project root folder), or a relative path to the root Lambda mount path
73+
within your project (e.g., `./functions`).
74+
75+
If you remove this flag, your Lambda code is deployed in the traditional way which is more in
76+
line with how things work in AWS, but also comes with a performance penalty: packaging the code,
7477
uploading it to the local S3 service, downloading it in the local Lambda API, extracting
7578
it, and finally copying/mounting it into a Docker container to run the Lambda. Mounting code
7679
from multiple projects is not supported with simple configuration, and you must use the
@@ -195,6 +198,7 @@ custom:
195198
196199
## Change Log
197200
201+
* v1.0.0: Allow specifying path for mountCode, to point to a relative Lambda mount path
198202
* v0.4.36: Add patch to avoid "TypeError" in AwsDeploy plugin on Serverless v3.4.0+
199203
* v0.4.35: Add config option to connect to additional Docker networks
200204
* v0.4.33: Fix parsing StepFunctions endpoint if the endpointInfo isn't defined

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-localstack",
3-
"version": "0.4.36",
3+
"version": "1.0.0",
44
"description": "Connect Serverless to LocalStack!",
55
"main": "src/index.js",
66
"scripts": {
@@ -18,8 +18,9 @@
1818
"type": "git",
1919
"url": "git+ssh://git@github.com/localstack/serverless-localstack"
2020
},
21-
"author": "Waldemar Hummer (whummer)",
21+
"author": "LocalStack Team <info@localstack.cloud>",
2222
"contributors": [
23+
"LocalStack Team <info@localstack.cloud>",
2324
"temyers",
2425
"Waldemar Hummer (whummer)",
2526
"Justin McCormick <me@justinmccormick.com>",

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const AWS = require('aws-sdk');
33
const fs = require('fs');
4+
const path = require('path');
45
const {promisify} = require('es6-promisify');
56
const exec = promisify(require('child_process').exec);
67

@@ -169,7 +170,7 @@ class LocalstackPlugin {
169170
}
170171

171172
// Patch plugin methods
172-
this.skipIfMountLambda('Package', 'packageService')
173+
this.skipIfMountLambda('Package', 'packageService');
173174
function compileFunction(functionName) {
174175
if (!this.shouldMountCode()) {
175176
return compileFunction._functionOriginal.apply(null, arguments);
@@ -184,6 +185,10 @@ class LocalstackPlugin {
184185
if (res.Type === 'AWS::Lambda::Function') {
185186
res.Properties.Code.S3Bucket = '__local__';
186187
res.Properties.Code.S3Key = process.cwd();
188+
const mountCode = this.config.lambda.mountCode;
189+
if (typeof mountCode === 'string' && mountCode.toLowerCase() !== 'true') {
190+
res.Properties.Code.S3Key = path.join(res.Properties.Code.S3Key, this.config.lambda.mountCode);
191+
}
187192
if (process.env.LAMBDA_MOUNT_CWD) {
188193
// Allow users to define a custom working directory for Lambda mounts.
189194
// For example, when deploying a Serverless app in a Linux VM (that runs Docker) on a
@@ -439,7 +444,7 @@ class LocalstackPlugin {
439444
}
440445
return containerID;
441446
}
442-
447+
443448
return getContainer().then(
444449
(containerID) => {
445450
if(containerID) {

0 commit comments

Comments
 (0)