Skip to content
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
4 changes: 4 additions & 0 deletions DEVELOPMENT_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ Move back to your SAM CLI directory and re-run init, If necessary: open requirem
Running Tests
-------------

### Unit testing with one Python version

If you're trying to do a quick run, it's ok to use the current python version. Run `make pr`.

### Unit testing with multiple Python versions

[tox](http://tox.readthedocs.io/en/latest/) is used to run tests against
Expand Down
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
3 changes: 2 additions & 1 deletion designs/sam_build_cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Success criteria for the change
- Python with PIP
- Golang with Go CLI
- Dotnetcore with DotNet CLI
2. Each Lambda function in SAM template gets built
2. Each Lambda function in SAM template gets built by default unless a `function_identifier` (LogicalID) is passed
to the build command
3. Produce stable builds (best effort): If the source files did not
change, built artifacts should not change.
4. Built artifacts should \"just work\" with `sam local` and
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ Debugging Golang functions

Golang function debugging is slightly different when compared to
Node.JS, Java, and Python. We require
[delve](https://github.com/derekparker/delve) as the debugger, and wrap
[delve](https://github.com/go-delve/delve) as the debugger, and wrap
your function with it at runtime. The debugger is run in headless mode,
listening on the debug port.

Expand All @@ -463,7 +463,7 @@ You must compile [delve]{.title-ref} to run in the container and provide
its local path via the [\--debugger-path]{.title-ref} argument. Build
delve locally as follows:

`GOARCH=amd64 GOOS=linux go build -o <delve folder path>/dlv github.com/derekparker/delve/cmd/dlv`
`GOARCH=amd64 GOOS=linux go build -o <delve folder path>/dlv github.com/go-delve/delve/cmd/dlv`

NOTE: The output path needs to end in [/dlv]{.title-ref}. The docker
container will expect the dlv binary to be in the \<delve folder path\>
Expand Down
2 changes: 1 addition & 1 deletion samcli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
SAM CLI version
"""

__version__ = '0.15.0'
__version__ = '0.16.0'
22 changes: 22 additions & 0 deletions samcli/commands/build/build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Context object used by build command
"""

import logging
import os
import shutil

Expand All @@ -14,6 +15,9 @@
from samcli.commands.local.lib.sam_function_provider import SamFunctionProvider
from samcli.commands._utils.template import get_template_data
from samcli.commands.exceptions import UserException
from samcli.local.lambdafn.exceptions import FunctionNotFound

LOG = logging.getLogger(__name__)


class BuildContext(object):
Expand All @@ -23,6 +27,7 @@ class BuildContext(object):
_BUILD_DIR_PERMISSIONS = 0o755

def __init__(self,
function_identifier,
template_file,
base_dir,
build_dir,
Expand All @@ -34,6 +39,7 @@ def __init__(self,
docker_network=None,
skip_pull_image=False):

self._function_identifier = function_identifier
self._template_file = template_file
self._base_dir = base_dir
self._build_dir = build_dir
Expand Down Expand Up @@ -128,3 +134,19 @@ def manifest_path_override(self):
@property
def mode(self):
return self._mode

@property
def functions_to_build(self):
if self._function_identifier:
function = self._function_provider.get(self._function_identifier)

if not function:
all_functions = [f.name for f in self._function_provider.get_all()]
available_function_message = "{} not found. Possible options in your template: {}" \
.format(self._function_identifier, all_functions)
LOG.info(available_function_message)
raise FunctionNotFound("Unable to find a Function with name '%s'", self._function_identifier)

return [function]

return self._function_provider.get_all()
29 changes: 18 additions & 11 deletions samcli/commands/build/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from samcli.lib.build.app_builder import ApplicationBuilder, BuildError, UnsupportedBuilderLibraryVersionError, \
ContainerBuildNotSupported
from samcli.lib.build.workflow_config import UnsupportedRuntimeException
from samcli.local.lambdafn.exceptions import FunctionNotFound
from samcli.commands._utils.template import move_template

LOG = logging.getLogger(__name__)
Expand All @@ -32,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 Expand Up @@ -81,8 +82,10 @@
@docker_common_options
@cli_framework_options
@aws_creds_options
@click.argument('function_identifier', required=False)
@pass_context
def cli(ctx,
function_identifier,
template,
base_dir,
build_dir,
Expand All @@ -96,11 +99,12 @@ def cli(ctx,

mode = _get_mode_value_from_envvar("SAM_BUILD_MODE", choices=["debug"])

do_cli(template, base_dir, build_dir, True, use_container, manifest, docker_network,
do_cli(function_identifier, template, base_dir, build_dir, True, use_container, manifest, docker_network,
skip_pull_image, parameter_overrides, mode) # pragma: no cover


def do_cli(template, # pylint: disable=too-many-locals
def do_cli(function_identifier, # pylint: disable=too-many-locals
template,
base_dir,
build_dir,
clean,
Expand All @@ -119,7 +123,8 @@ def do_cli(template, # pylint: disable=too-many-locals
if use_container:
LOG.info("Starting Build inside a container")

with BuildContext(template,
with BuildContext(function_identifier,
template,
base_dir,
build_dir,
clean=clean,
Expand All @@ -129,14 +134,16 @@ def do_cli(template, # pylint: disable=too-many-locals
docker_network=docker_network,
skip_pull_image=skip_pull_image,
mode=mode) as ctx:
try:
builder = ApplicationBuilder(ctx.functions_to_build,
ctx.build_dir,
ctx.base_dir,
manifest_path_override=ctx.manifest_path_override,
container_manager=ctx.container_manager,
mode=ctx.mode)
except FunctionNotFound as ex:
raise UserException(str(ex))

builder = ApplicationBuilder(ctx.function_provider,
ctx.build_dir,
ctx.base_dir,
manifest_path_override=ctx.manifest_path_override,
container_manager=ctx.container_manager,
mode=ctx.mode
)
try:
artifacts = builder.build()
modified_template = builder.update_template(ctx.template_dict,
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
10 changes: 5 additions & 5 deletions samcli/lib/build/app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ApplicationBuilder(object):
"""

def __init__(self,
function_provider,
functions_to_build,
build_dir,
base_dir,
manifest_path_override=None,
Expand All @@ -61,8 +61,8 @@ def __init__(self,

Parameters
----------
function_provider : samcli.commands.local.lib.sam_function_provider.SamFunctionProvider
Provider that can vend out functions available in the SAM template
functions_to_build: Iterator
Iterator that can vend out functions available in the SAM template

build_dir : str
Path to the directory where we will be storing built artifacts
Expand All @@ -79,7 +79,7 @@ def __init__(self,
mode : str
Optional, name of the build mode to use ex: 'debug'
"""
self._function_provider = function_provider
self._functions_to_build = functions_to_build
self._build_dir = build_dir
self._base_dir = base_dir
self._manifest_path_override = manifest_path_override
Expand All @@ -100,7 +100,7 @@ def build(self):

result = {}

for lambda_function in self._function_provider.get_all():
for lambda_function in self._functions_to_build:

LOG.info("Building resource '%s'", lambda_function.name)
result[lambda_function.name] = self._build_function(lambda_function.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
20 changes: 20 additions & 0 deletions samcli/local/apigw/local_apigw_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ def _parse_lambda_output(lambda_output, binary_types, flask_request):
LOG.error(message)
raise TypeError(message)

# API Gateway only accepts statusCode, body, headers, and isBase64Encoded in
# a response shape.
invalid_keys = LocalApigwService._invalid_apig_response_keys(json_output)
if bool(invalid_keys):
msg = "Invalid API Gateway Response Keys: " + str(invalid_keys) + " in " + str(json_output)
LOG.error(msg)
raise ValueError(msg)

# If the customer doesn't define Content-Type default to application/json
if "Content-Type" not in headers:
LOG.info("No Content-Type given. Defaulting to 'application/json'.")
Expand All @@ -230,6 +238,18 @@ def _parse_lambda_output(lambda_output, binary_types, flask_request):

return status_code, headers, body

@staticmethod
def _invalid_apig_response_keys(output):
allowable = {
"statusCode",
"body",
"headers",
"isBase64Encoded"
}
# In Python 2.7, need to explicitly make the Dictionary keys into a set
invalid_keys = set(output.keys()) - allowable
return invalid_keys

@staticmethod
def _should_base64_decode_body(binary_types, flask_request, lamba_response_headers, is_base_64_encoded):
"""
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
Loading