Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update README and add some example for npm build
  • Loading branch information
Massimo Maino committed Mar 26, 2022
commit 993a1e2ea6f2a9e8531e41703b55fbb3a5cef0d4
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,9 @@ source_path = [
]
```

Few notes:
*Few notes:*

- If you specify a source path as a string that references a folder and the runtime is either python or nodejs, the build process will automatically build python and nodejs dependencies if `requirements.txt` or `package.json` file will be found in the source folder. If you want to customize this behavior, please use the object notation as explained below.
- All arguments except `path` are optional.
- `patterns` - List of Python regex filenames should satisfy. Default value is "include everything" which is equal to `patterns = [".*"]`. This can also be specified as multiline heredoc string (no comments allowed). Some examples of valid patterns:

Expand All @@ -447,10 +448,12 @@ Few notes:
!abc/def/hgk/.* # Filter out again in abc/def/hgk sub folder
```

- `commands` - List of commands to run. If specified, this argument overrides `pip_requirements`.
- `commands` - List of commands to run. If specified, this argument overrides `pip_requirements` and `npm_requirements`.
- `:zip [source] [destination]` is a special command which creates content of current working directory (first argument) and places it inside of path (second argument).
- `pip_requirements` - Controls whether to execute `pip install`. Set to `false` to disable this feature, `true` to run `pip install` with `requirements.txt` found in `path`. Or set to another filename which you want to use instead.
- `pip_tmp_dir` - Set the base directory to make the temporary directory for pip installs. Can be useful for Docker in Docker builds.
- `npm_requirements` - Controls whether to execute `npm install`. Set to `false` to disable this feature, `true` to run `npm install` with `package.json` found in `path`. Or set to another filename which you want to use instead.
- `npm_tmp_dir` - Set the base directory to make the temporary directory for npm installs. Can be useful for Docker in Docker builds.
- `prefix_in_zip` - If specified, will be used as a prefix inside zip-archive. By default, everything installs into the root of zip-archive.

### Building in Docker
Expand Down
3 changes: 3 additions & 0 deletions examples/build-package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Note that this example may create resources which cost money. Run `terraform des
| <a name="module_package_with_docker"></a> [package\_with\_docker](#module\_package\_with\_docker) | ../../ | n/a |
| <a name="module_package_with_patterns"></a> [package\_with\_patterns](#module\_package\_with\_patterns) | ../../ | n/a |
| <a name="module_package_with_pip_requirements_in_docker"></a> [package\_with\_pip\_requirements\_in\_docker](#module\_package\_with\_pip\_requirements\_in\_docker) | ../../ | n/a |
| <a name="module_package_dir_with_npm_install"></a> [package\_dir\_with\_npm\_install](#module\_package\_dir\_with\_npm\_install) | ../../ | n/a |
| <a name="module_package_dir_without_npm_install"></a> [package\_dir\_without\_npm\_install](#module\_package\_dir\_without\_npm\_install) | ../../ | n/a |
| <a name="module_package_with_npm_requirements_in_docker"></a> [package\_with\_npm\_requirements\_in_docker](#module\_package\_with\_npm\_requirements\_in_docker) | ../../ | n/a |

## Resources

Expand Down
38 changes: 38 additions & 0 deletions examples/build-package/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,44 @@ module "package_with_docker" {
docker_image = "lambci/lambda:build-python3.8"
}

# Create zip-archive of a single directory where "npm install" will also be executed (default for nodejs runtime)
module "package_dir_with_npm_install" {
source = "../../"

create_function = false

runtime = "nodejs14.x"
source_path = "${path.module}/../fixtures/nodejs14.x-app1"
}

# Create zip-archive of a single directory without running "pip install" (which is default for python runtime)
module "package_dir_without_npm_install" {
source = "../../"

create_function = false

runtime = "nodejs14.x"
source_path = [
{
path = "${path.module}/../fixtures/nodejs14.x-app1"
npm_requirements = false
# npm_requirements = true # Will run "npm install" with default requirements.txt
}
]
}

# Create zip-archive of a single directory where "npm install" will also be executed using docker
module "package_with_npm_requirements_in_docker" {
source = "../../"

create_function = false

runtime = "nodejs14.x"
source_path = "${path.module}/../fixtures/nodejs14.x-app1"
build_in_docker = true
hash_extra = "something-unique-to-not-conflict-with-module.package_dir_with_npm_install"
}

################################
# Build package in Docker and
# use it to deploy Lambda Layer
Expand Down
16 changes: 16 additions & 0 deletions examples/fixtures/nodejs14.x-app1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

module.exports.hello = async (event) => {
console.log(event);
return {
statusCode: 200,
body: JSON.stringify(
{
message: `Go Serverless v3.0! Your Nodejs function executed successfully!`,
input: event,
},
null,
2
),
};
};
8 changes: 8 additions & 0 deletions examples/fixtures/nodejs14.x-app1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "nodejs14.x-app1",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"requests": "^0.3.0"
}
}