Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nodejs10.x): support new nodejs10.x runtime #1175

Merged
merged 1 commit into from
May 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Project Status
- \[x\] `nodejs4.3`
- \[x\] `nodejs6.10`
- \[x\] `nodejs8.10`
- \[x\] `nodejs10.x`
- \[x\] `java8`
- \[x\] `python2.7`
- \[x\] `python3.6`
Expand All @@ -91,6 +92,7 @@ Project Status
- \[x\] `nodejs4.3`
- \[x\] `nodejs6.10`
- \[x\] `nodejs8.10`
- \[x\] `nodejs10.x`
- \[x\] `java8`
- \[x\] `python2.7`
- \[x\] `python3.6`
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/build/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Supported Runtimes
------------------
1. Python 2.7, 3.6, 3.7 using PIP\n
2. Nodejs 8.10, 6.10 using NPM\n
2. Nodejs 10.x, 8.10, 6.10 using NPM\n
3. Ruby 2.5 using Bundler\n
4. Java 8 using Gradle\n
5. Dotnetcore2.0 and 2.1 using Dotnet CLI (without --use-container flag)\n
Expand Down
4 changes: 3 additions & 1 deletion samcli/commands/init/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def do_cli(ctx, location, runtime, dependency_manager, output_dir, name, no_inpu
""".format(output_dir=output_dir, name=name)

no_build_step_required = (
"python", "python3.7", "python3.6", "python2.7", "nodejs", "nodejs4.3", "nodejs6.10", "nodejs8.10", "ruby2.5")
"python", "python3.7", "python3.6", "python2.7", "nodejs",
"nodejs4.3", "nodejs6.10", "nodejs8.10", "nodejs10.x", "ruby2.5"
)
next_step_msg = no_build_msg if runtime in no_build_step_required else build_msg

try:
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/local/invoke/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from samcli.commands.validate.lib.exceptions import InvalidSamDocumentException
from samcli.commands.local.lib.exceptions import OverridesNotWellDefinedError
from samcli.local.docker.manager import DockerImagePullFailedException
from samcli.local.docker.lambda_container import DebuggingNotSupported
from samcli.local.docker.lambda_debug_entrypoint import DebuggingNotSupported


LOG = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/local/start_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from samcli.commands.local.lib.local_api_service import LocalApiService
from samcli.commands.validate.lib.exceptions import InvalidSamDocumentException
from samcli.commands.local.lib.exceptions import OverridesNotWellDefinedError
from samcli.local.docker.lambda_container import DebuggingNotSupported
from samcli.local.docker.lambda_debug_entrypoint import DebuggingNotSupported

LOG = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/local/start_lambda/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from samcli.commands.local.lib.local_lambda_service import LocalLambdaService
from samcli.commands.validate.lib.exceptions import InvalidSamDocumentException
from samcli.commands.local.lib.exceptions import OverridesNotWellDefinedError
from samcli.local.docker.lambda_container import DebuggingNotSupported
from samcli.local.docker.lambda_debug_entrypoint import DebuggingNotSupported


LOG = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions samcli/lib/build/workflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def get_workflow_config(runtime, code_dir, project_dir):
"nodejs4.3": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"nodejs6.10": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"nodejs8.10": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"nodejs10.x": BasicWorkflowSelector(NODEJS_NPM_CONFIG),
"ruby2.5": BasicWorkflowSelector(RUBY_BUNDLER_CONFIG),
"dotnetcore2.0": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
"dotnetcore2.1": BasicWorkflowSelector(DOTNET_CLIPACKAGE_CONFIG),
Expand Down
2 changes: 1 addition & 1 deletion samcli/local/common/runtime_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"nodejs": [
{
"runtimes": ["nodejs8.10"],
"runtimes": ["nodejs8.10", "nodejs10.x"],
"dependency_manager": "npm",
"init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-nodejs"),
"build": True
Expand Down
140 changes: 8 additions & 132 deletions samcli/local/docker/lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Represents Lambda runtime containers.
"""
import logging
import json

from samcli.local.docker.lambda_debug_entrypoint import LambdaDebugEntryPoint
from .container import Container
from .lambda_image import Runtime

Expand All @@ -25,6 +25,9 @@ class LambdaContainer(Container):
_DEBUGGER_VOLUME_MOUNT_PATH = "/tmp/lambci_debug_files"
_DEFAULT_CONTAINER_DBG_GO_PATH = _DEBUGGER_VOLUME_MOUNT_PATH + "/dlv"

# Options for selecting debug entry point
_DEBUG_ENTRYPOINT_OPTIONS = {"delvePath": _DEFAULT_CONTAINER_DBG_GO_PATH}

# This is the dictionary that represents where the debugger_path arg is mounted in docker to as readonly.
_DEBUGGER_VOLUME_MOUNT = {"bind": _DEBUGGER_VOLUME_MOUNT_PATH, "mode": "ro"}

Expand Down Expand Up @@ -174,10 +177,6 @@ def _get_entry_point(runtime, debug_options=None): # pylint: disable=too-many-b
if not debug_options:
return None

if runtime not in LambdaContainer._supported_runtimes():
raise DebuggingNotSupported(
"Debugging is not currently supported for {}".format(runtime))

debug_port = debug_options.debug_port
debug_args_list = []

Expand All @@ -186,130 +185,7 @@ def _get_entry_point(runtime, debug_options=None): # pylint: disable=too-many-b

# configs from: https://github.com/lambci/docker-lambda
# to which we add the extra debug mode options
entrypoint = None
if runtime == Runtime.java8.value:

entrypoint = ["/usr/bin/java"] \
+ debug_args_list \
+ [
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=" + str(debug_port),
"-XX:MaxHeapSize=2834432k",
"-XX:MaxMetaspaceSize=163840k",
"-XX:ReservedCodeCacheSize=81920k",
"-XX:+UseSerialGC",
# "-Xshare:on", doesn't work in conjunction with the debug options
"-XX:-TieredCompilation",
"-Djava.net.preferIPv4Stack=true",
"-jar",
"/var/runtime/lib/LambdaJavaRTEntry-1.0.jar",
]

elif runtime in (Runtime.dotnetcore20.value, Runtime.dotnetcore21.value):
entrypoint = ["/var/lang/bin/dotnet"] \
+ debug_args_list \
+ [
"/var/runtime/MockBootstraps.dll",
"--debugger-spin-wait"
]

elif runtime == Runtime.go1x.value:
entrypoint = ["/var/runtime/aws-lambda-go"] \
+ debug_args_list \
+ [
"-debug=true",
"-delvePort=" + str(debug_port),
"-delvePath=" + LambdaContainer._DEFAULT_CONTAINER_DBG_GO_PATH,
]

elif runtime == Runtime.nodejs.value:

entrypoint = ["/usr/bin/node"] \
+ debug_args_list \
+ [
"--debug-brk=" + str(debug_port),
"--nolazy",
"--max-old-space-size=1229",
"--max-new-space-size=153",
"--max-executable-size=153",
"--expose-gc",
"/var/runtime/node_modules/awslambda/bin/awslambda",
]

elif runtime == Runtime.nodejs43.value:

entrypoint = ["/usr/local/lib64/node-v4.3.x/bin/node"] \
+ debug_args_list \
+ [
"--debug-brk=" + str(debug_port),
"--nolazy",
"--max-old-space-size=2547",
"--max-semi-space-size=150",
"--max-executable-size=160",
"--expose-gc",
"/var/runtime/node_modules/awslambda/index.js",
]

elif runtime == Runtime.nodejs610.value:

entrypoint = ["/var/lang/bin/node"] \
+ debug_args_list \
+ [
"--debug-brk=" + str(debug_port),
"--nolazy",
"--max-old-space-size=2547",
"--max-semi-space-size=150",
"--max-executable-size=160",
"--expose-gc",
"/var/runtime/node_modules/awslambda/index.js",
]

elif runtime == Runtime.nodejs810.value:

entrypoint = ["/var/lang/bin/node"] \
+ debug_args_list \
+ [
# Node8 requires the host to be explicitly set in order to bind to localhost
# instead of 127.0.0.1. https://github.com/nodejs/node/issues/11591#issuecomment-283110138
"--inspect-brk=0.0.0.0:" + str(debug_port),
"--nolazy",
"--expose-gc",
"--max-semi-space-size=150",
"--max-old-space-size=2707",
"/var/runtime/node_modules/awslambda/index.js",
]

elif runtime == Runtime.python27.value:

entrypoint = ["/usr/bin/python2.7"] \
+ debug_args_list \
+ [
"/var/runtime/awslambda/bootstrap.py"
]

elif runtime == Runtime.python36.value:

entrypoint = ["/var/lang/bin/python3.6"] \
+ debug_args_list \
+ [
"/var/runtime/awslambda/bootstrap.py"
]

elif runtime == Runtime.python37.value:
entrypoint = ["/var/rapid/init",
"--bootstrap",
"/var/lang/bin/python3.7",
"--bootstrap-args",
json.dumps(debug_args_list + ["/var/runtime/bootstrap"])
]

return entrypoint

@staticmethod
def _supported_runtimes():
return {Runtime.java8.value, Runtime.dotnetcore20.value, Runtime.dotnetcore21.value, Runtime.go1x.value,
Runtime.nodejs.value, Runtime.nodejs43.value, Runtime.nodejs610.value, Runtime.nodejs810.value,
Runtime.python27.value, Runtime.python36.value, Runtime.python37.value}


class DebuggingNotSupported(Exception):
pass
return LambdaDebugEntryPoint.get_entry_point(debug_port=debug_port,
debug_args_list=debug_args_list,
runtime=runtime,
options=LambdaContainer._DEBUG_ENTRYPOINT_OPTIONS)
148 changes: 148 additions & 0 deletions samcli/local/docker/lambda_debug_entrypoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
"""
Represents Lambda debug entrypoints.
"""

import json

from samcli.local.docker.lambda_image import Runtime


class DebuggingNotSupported(Exception):
pass


class LambdaDebugEntryPoint(object):

@staticmethod
def get_entry_point(debug_port, debug_args_list, runtime, options):

entrypoint_mapping = {
Runtime.java8.value:
["/usr/bin/java"] +
debug_args_list +
[
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,quiet=y,address=" + str(debug_port),
"-XX:MaxHeapSize=2834432k",
"-XX:MaxMetaspaceSize=163840k",
"-XX:ReservedCodeCacheSize=81920k",
"-XX:+UseSerialGC",
# "-Xshare:on", doesn't work in conjunction with the debug options
"-XX:-TieredCompilation",
"-Djava.net.preferIPv4Stack=true",
"-jar",
"/var/runtime/lib/LambdaJavaRTEntry-1.0.jar"
],

Runtime.dotnetcore20.value:
["/var/lang/bin/dotnet"] + \
debug_args_list + \
[
"/var/runtime/MockBootstraps.dll",
"--debugger-spin-wait"
],

Runtime.dotnetcore21.value:
["/var/lang/bin/dotnet"] + \
debug_args_list + \
[
"/var/runtime/MockBootstraps.dll",
"--debugger-spin-wait"
],
Runtime.go1x.value:
["/var/runtime/aws-lambda-go"] + \
debug_args_list + \
[
"-debug=true",
"-delvePort=" + str(debug_port),
"-delvePath=" + options.get("delvePath"),
],
Runtime.nodejs.value:
["/usr/bin/node"] + \
debug_args_list + \
[
"--debug-brk=" + str(debug_port),
"--nolazy",
"--max-old-space-size=1229",
"--max-new-space-size=153",
"--max-executable-size=153",
"--expose-gc",
"/var/runtime/node_modules/awslambda/bin/awslambda",
],
Runtime.nodejs43.value:
["/usr/local/lib64/node-v4.3.x/bin/node"] + \
debug_args_list + \
[
"--debug-brk=" + str(debug_port),
"--nolazy",
"--max-old-space-size=2547",
"--max-semi-space-size=150",
"--max-executable-size=160",
"--expose-gc",
"/var/runtime/node_modules/awslambda/index.js",
],
Runtime.nodejs610.value:
["/var/lang/bin/node"] + \
debug_args_list + \
[
"--debug-brk=" + str(debug_port),
"--nolazy",
"--max-old-space-size=2547",
"--max-semi-space-size=150",
"--max-executable-size=160",
"--expose-gc",
"/var/runtime/node_modules/awslambda/index.js",
],
Runtime.nodejs810.value:
["/var/lang/bin/node"] + \
debug_args_list + \
[
# Node8 requires the host to be explicitly set in order to bind to localhost
# instead of 127.0.0.1. https://github.com/nodejs/node/issues/11591#issuecomment-283110138
"--inspect-brk=0.0.0.0:" + str(debug_port),
"--nolazy",
"--expose-gc",
"--max-semi-space-size=150",
"--max-old-space-size=2707",
"/var/runtime/node_modules/awslambda/index.js",
],
Runtime.nodejs10x.value:
["/var/rapid/init",
"--bootstrap",
"/var/lang/bin/node",
"--bootstrap-args",
json.dumps(debug_args_list +
[
"--inspect-brk=0.0.0.0:" + str(debug_port),
"--nolazy",
"--expose-gc",
"--max-http-header-size",
"81920",
"/var/runtime/index.js"
]
)
],
Runtime.python27.value:
["/usr/bin/python2.7"] + \
debug_args_list + \
[
"/var/runtime/awslambda/bootstrap.py"
],
Runtime.python36.value:
["/var/lang/bin/python3.6"] +
debug_args_list + \
[
"/var/runtime/awslambda/bootstrap.py"
],
Runtime.python37.value:
["/var/rapid/init",
"--bootstrap",
"/var/lang/bin/python3.7",
"--bootstrap-args",
json.dumps(debug_args_list + ["/var/runtime/bootstrap"])
]
}
try:
return entrypoint_mapping[runtime]
except KeyError:
raise DebuggingNotSupported(
"Debugging is not currently supported for {}".format(runtime))
Loading