Skip to content

Commit

Permalink
Merge pull request #1669 from awslabs/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jfuss committed Dec 17, 2019
2 parents a047015 + 2744c3c commit dbf1a96
Show file tree
Hide file tree
Showing 42 changed files with 407 additions and 993 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ environment:

install:

- "SET PATH=%PYTHON_HOME%;%PATH%"
- "echo %PYTHON_HOME%"
- "echo %PATH%"
- "python --version"

# Upgrade setuptools, wheel and virtualenv
- "python -m pip install --upgrade setuptools wheel virtualenv"

# Create new virtual environment with chosen python version and activate it
- "python -m virtualenv venv"
- "venv\\Scripts\\activate"
- "python --version"

# Actually install SAM CLI's dependencies
- "pip install -e \".[dev]\""

# setup Java, Maven and Gradle
- "refreshenv"
- "choco install maven -y --force"
Expand All @@ -52,9 +36,22 @@ install:
# Echo final Path
- "echo %PATH%"

# validate ssl works with ruby
- "ruby -ropen-uri -e 'eval open(\"https://git.io/vQhWq\").read'"

- "set PATH=%PYTHON_HOME%;%PYTHON_HOME%\\Scripts;%PYTHON_HOME%\\bin;%PATH%"
- "echo %PYTHON_HOME%"
- "echo %PATH%"
- "python --version"

# Actually install SAM CLI's dependencies
- "pip install -e \".[dev]\""

test_script:
# Reactivate virtualenv before running tests
- "venv\\Scripts\\activate"
- "pytest -vv tests/integration/buildcmd/test_build_cmd.py -k test_building_java8_in_process"
- "SET JAVA_HOME=C:\\Program Files\\Java\\jdk11"
- "pytest -vv tests/integration/buildcmd/test_build_cmd.py -k test_building_java11_in_process"

# Run Ruby in-process builds
- "pytest -vv tests/integration/buildcmd/test_build_cmd.py -k test_building_ruby_in_process"
1 change: 1 addition & 0 deletions appveyor-windows-build-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ install:

# Make sure the temp directory exists for Python to use.
# Install python3.8
- "choco install chocolatey-core.extension --version 1.3.3 --force -y"
- "choco install python3 --version 3.8.0"
- "C:\\Python38\\python.exe -m pip freeze"
- "refreshenv"
Expand Down
1 change: 1 addition & 0 deletions appveyor-windows-build-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ install:
- "pip install -e \".[dev]\""

# setup Ruby
- "choco install chocolatey-core.extension --version 1.3.3 --force -y"
- "choco install ruby --version 2.5.3.1 --force -y"
- "refreshenv"
- "ruby --version"
Expand Down
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ environment:
matrix:

- PYTHON_HOME: "C:\\Python36-x64"
PYTHON_VERSION: '3.6.8'
PYTHON_VERSION: '3.6.9'
PYTHON_ARCH: '64'
NOSE_PARAMETERIZED_NO_WARN: 1
INSTALL_PY_37_PIP: 1
Expand Down Expand Up @@ -93,7 +93,6 @@ for:
- sh: "sudo apt-get -y install python3.6"
- sh: "sudo apt-get -y install python2.7"
- sh: "sudo apt-get -y install python3.7"
- sh: "sudo apt-get update"
- sh: "sudo apt-get -y install python3.8"

- sh: "which python3.8"
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.37.0"
__version__ = "0.38.0"
12 changes: 11 additions & 1 deletion samcli/commands/deploy/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,17 @@ def do_cli(

read_config_showcase(template_file=template_file)

guided_stack_name, guided_s3_bucket, guided_s3_prefix, guided_region, guided_profile, changeset_decision, _capabilities, _parameter_overrides, save_to_config = guided_deploy(
(
guided_stack_name,
guided_s3_bucket,
guided_s3_prefix,
guided_region,
guided_profile,
changeset_decision,
_capabilities,
_parameter_overrides,
save_to_config,
) = guided_deploy(
stack_name, s3_bucket, region, profile, confirm_changeset, _parameter_override_keys, parameter_overrides
)

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 @@ -116,7 +116,7 @@ def do_cli( # pylint: disable=R0914
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_debug_entrypoint import DebuggingNotSupported
from samcli.local.docker.lambda_debug_settings import DebuggingNotSupported

LOG.debug("local invoke command is called")

Expand Down
39 changes: 24 additions & 15 deletions samcli/commands/local/lib/local_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def __init__(
self.aws_region = aws_region
self.env_vars_values = env_vars_values or {}
self.debug_context = debug_context
self._boto3_session_creds = None
self._boto3_region = None

def invoke(self, function_name, event, stdout=None, stderr=None):
"""
Expand Down Expand Up @@ -205,6 +207,22 @@ def _make_env_vars(self, function):
aws_creds=aws_creds,
)

def _get_session_creds(self):
if self._boto3_session_creds is None:
# to pass command line arguments for region & profile to setup boto3 default session
LOG.debug("Loading AWS credentials from session with profile '%s'", self.aws_profile)
session = boto3.session.Session(profile_name=self.aws_profile, region_name=self.aws_region)

# check for region_name in session and cache
if hasattr(session, "region_name") and session.region_name:
self._boto3_region = session.region_name

# don't set cached session creds if there is not a session
if session:
self._boto3_session_creds = session.get_credentials()

return self._boto3_session_creds

def get_aws_creds(self):
"""
Returns AWS credentials obtained from the shell environment or given profile
Expand All @@ -215,26 +233,17 @@ def get_aws_creds(self):
"""
result = {}

# to pass command line arguments for region & profile to setup boto3 default session
LOG.debug("Loading AWS credentials from session with profile '%s'", self.aws_profile)
# boto3.session.Session is not thread safe. To ensure we do not run into a race condition with start-lambda
# or start-api, we create the session object here on every invoke.
session = boto3.session.Session(profile_name=self.aws_profile, region_name=self.aws_region)

if not session:
return result

# Load the credentials from profile/environment
creds = session.get_credentials()
creds = self._get_session_creds()

# After loading credentials, region name might be available here.
if self._boto3_region:
result["region"] = self._boto3_region

if not creds:
# If we were unable to load credentials, then just return empty. We will use the default
# If we were unable to load credentials, then just return result. We will use the default
return result

# After loading credentials, region name might be available here.
if hasattr(session, "region_name") and session.region_name:
result["region"] = session.region_name

# Only add the key, if its value is present
if hasattr(creds, "access_key") and creds.access_key:
result["key"] = creds.access_key
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 @@ -115,7 +115,7 @@ def do_cli( # pylint: disable=R0914
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_debug_entrypoint import DebuggingNotSupported
from samcli.local.docker.lambda_debug_settings import DebuggingNotSupported

LOG.debug("local start-api command is called")

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 @@ -124,7 +124,7 @@ def do_cli( # pylint: disable=R0914
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_debug_entrypoint import DebuggingNotSupported
from samcli.local.docker.lambda_debug_settings import DebuggingNotSupported

LOG.debug("local start_lambda command is called")

Expand Down
10 changes: 10 additions & 0 deletions samcli/lib/package/artifact_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ def upload_local_artifacts(resource_id, resource_dict, property_name, parent_dir
raise exceptions.InvalidLocalPathError(resource_id=resource_id, property_name=property_name, local_path=local_path)


def resource_not_packageable(resource_dict):
inline_code = jmespath.search("InlineCode", resource_dict)
if inline_code is not None:
return True
return False


def zip_and_upload(local_path, uploader):
with zip_folder(local_path) as zip_file:
return uploader.upload_with_dedup(zip_file)
Expand Down Expand Up @@ -235,6 +242,9 @@ def export(self, resource_id, resource_dict, parent_dir):
if resource_dict is None:
return

if resource_not_packageable(resource_dict):
return

property_value = jmespath.search(self.PROPERTY_NAME, resource_dict)

if not property_value and not self.PACKAGE_NULL_PROPERTY:
Expand Down
10 changes: 1 addition & 9 deletions samcli/local/common/runtime_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@
"dependency_manager": "npm",
"init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-nodejs"),
"build": True,
},
{
"runtimes": ["nodejs6.10"],
"dependency_manager": "npm",
"init_location": os.path.join(_templates, "cookiecutter-aws-sam-hello-nodejs6"),
"build": True,
},
}
],
"dotnet": [
{
Expand Down Expand Up @@ -83,7 +77,6 @@
"nodejs12.x": ["npm"],
"nodejs10.x": ["npm"],
"nodejs8.10": ["npm"],
"nodejs6.10": ["npm"],
"dotnetcore2.1": ["cli-package"],
"dotnetcore2.0": ["cli-package"],
"dotnetcore1.0": ["cli-package"],
Expand Down Expand Up @@ -115,7 +108,6 @@
# older nodejs runtimes
"nodejs10.x",
"nodejs8.10",
"nodejs6.10",
# older python runtimes
"python3.7",
"python3.6",
Expand Down
17 changes: 11 additions & 6 deletions samcli/local/docker/lambda_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import logging

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

Expand Down Expand Up @@ -71,11 +71,16 @@ def __init__(

image = LambdaContainer._get_image(image_builder, runtime, layers)
ports = LambdaContainer._get_exposed_ports(debug_options)
entry = LambdaContainer._get_entry_point(runtime, debug_options)
entry, debug_env_vars = LambdaContainer._get_debug_settings(runtime, debug_options)
additional_options = LambdaContainer._get_additional_options(runtime, debug_options)
additional_volumes = LambdaContainer._get_additional_volumes(debug_options)
cmd = [handler]

if not env_vars:
env_vars = {}

env_vars = {**env_vars, **debug_env_vars}

super(LambdaContainer, self).__init__(
image,
cmd,
Expand Down Expand Up @@ -168,7 +173,7 @@ def _get_image(image_builder, runtime, layers):
return image_builder.build(runtime, layers)

@staticmethod
def _get_entry_point(runtime, debug_options=None): # pylint: disable=too-many-branches
def _get_debug_settings(runtime, debug_options=None): # pylint: disable=too-many-branches
"""
Returns the entry point for the container. The default value for the entry point is already configured in the
Dockerfile. We override this default specifically when enabling debugging. The overridden entry point includes
Expand All @@ -181,11 +186,11 @@ def _get_entry_point(runtime, debug_options=None): # pylint: disable=too-many-b
"""

if not debug_options:
return None
return None, {}

debug_ports = debug_options.debug_ports
if not debug_ports:
return None
return None, {}

debug_port = debug_ports[0]
debug_args_list = []
Expand All @@ -195,7 +200,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
return LambdaDebugEntryPoint.get_entry_point(
return LambdaDebugSettings.get_debug_settings(
debug_port=debug_port,
debug_args_list=debug_args_list,
runtime=runtime,
Expand Down
Loading

0 comments on commit dbf1a96

Please sign in to comment.