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

chore: Update feature branch #5464

Merged
merged 6 commits into from
Jul 7, 2023
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: 2 additions & 2 deletions .github/workflows/automated-updates-to-sam-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- uses: actions/setup-python@v4 # used for make update-reproducible-reqs below
with:
python-version: |
3.7
3.8
3.11

- name: Update aws-sam-translator & commit
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
- uses: actions/setup-python@v4 # used for make update-reproducible-reqs below
with:
python-version: |
3.7
3.8
3.11

- name: Upgrade aws_lambda_builders & commit
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ update-reproducible-linux-reqs:
venv-update-reproducible-linux/bin/pip-compile --generate-hashes --allow-unsafe -o requirements/reproducible-linux.txt

update-reproducible-mac-reqs:
python3.7 -m venv venv-update-reproducible-mac
python3.8 -m venv venv-update-reproducible-mac
venv-update-reproducible-mac/bin/pip install --upgrade pip-tools pip
venv-update-reproducible-mac/bin/pip install -r requirements/base.txt
venv-update-reproducible-mac/bin/pip-compile --generate-hashes --allow-unsafe -o requirements/reproducible-mac.txt
Expand Down
9 changes: 8 additions & 1 deletion appveyor-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ install:
# Echo final Path
- "echo %PATH%"

- "IF DEFINED BY_CANARY ECHO Logging in Public ECR && aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws"
# use amazon-ecr-credential-helper
- choco install amazon-ecr-credential-helper
- ps: "
$docker_config = Get-Content $env:HOME/.docker/config.json -raw | ConvertFrom-Json;
$docker_config.credsStore = 'ecr-login';
$docker_config | ConvertTo-Json | set-content $env:HOME/.docker/config.json;
"
- ps: "get-content $env:HOME/.docker/config.json"

# claim some disk space before starting the tests
- "docker system prune -a -f"
Expand Down
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ filterwarnings =
error
ignore::DeprecationWarning:docker
default::ResourceWarning
; The following deprecation warnings are treated as failures unless we explicitly tell pytest not to
; Remove once we no longer support python3.7
ignore::boto3.exceptions.PythonDeprecationWarning

7 changes: 5 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
chevron~=0.12
click~=8.0
# 8.1.4 of Click has an issue with the typing breaking the linter - https://github.com/pallets/click/issues/2558
click~=8.0,!=8.1.4
Flask<2.3
#Need to add latest lambda changes which will return invoke mode details
boto3>=1.26.109,==1.*
jmespath~=1.0.1
ruamel_yaml~=0.17.32
PyYAML>=5.4.1,==5.*
cookiecutter~=2.1.1
aws-sam-translator==1.70.0
aws-sam-translator==1.71.0
#docker minor version updates can include breaking changes. Auto update micro version only.
docker~=6.1.0
dateparser~=1.1
Expand All @@ -18,6 +19,8 @@ tomlkit==0.11.8
watchdog==2.1.2
rich~=13.3.3
pyopenssl~=23.2.0
# Pin to <4.18 to until SAM-T no longer uses RefResolver
jsonschema<4.18

# Needed for supporting Protocol in Python 3.7, Protocol class became public with python3.8
typing_extensions~=4.4.0
Expand Down
6 changes: 3 additions & 3 deletions requirements/reproducible-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ aws-lambda-builders==1.34.0 \
--hash=sha256:0790f7e9b7ee7286b96fbcf49450c5be0341bb7cb852ca7d74beae190139eb48 \
--hash=sha256:20456a942a417407b42ecf8ab7fce6a47306fd063051e7cb09d02d1be24d5cf3
# via aws-sam-cli (setup.py)
aws-sam-translator==1.70.0 \
--hash=sha256:753288eda07b057e5350773b7617076962b59404d49cd05e2259ac96a7694436 \
--hash=sha256:a2df321607d29791893707ef2ded9e79be00dbb71ac430696f6e6d7d0b0301a5
aws-sam-translator==1.71.0 \
--hash=sha256:17fb87c8137d8d49e7a978396b2b3b279211819dee44618415aab1e99c2cb659 \
--hash=sha256:a3ea80aeb116d7978b26ac916d2a5a24d012b742bf28262b17769c4b886e8fba
# via
# aws-sam-cli (setup.py)
# cfn-lint
Expand Down
19 changes: 5 additions & 14 deletions requirements/reproducible-mac.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.7
# This file is autogenerated by pip-compile with Python 3.8
# by the following command:
#
# pip-compile --allow-unsafe --generate-hashes --output-file=requirements/reproducible-mac.txt
Expand All @@ -19,9 +19,9 @@ aws-lambda-builders==1.34.0 \
--hash=sha256:0790f7e9b7ee7286b96fbcf49450c5be0341bb7cb852ca7d74beae190139eb48 \
--hash=sha256:20456a942a417407b42ecf8ab7fce6a47306fd063051e7cb09d02d1be24d5cf3
# via aws-sam-cli (setup.py)
aws-sam-translator==1.70.0 \
--hash=sha256:753288eda07b057e5350773b7617076962b59404d49cd05e2259ac96a7694436 \
--hash=sha256:a2df321607d29791893707ef2ded9e79be00dbb71ac430696f6e6d7d0b0301a5
aws-sam-translator==1.71.0 \
--hash=sha256:17fb87c8137d8d49e7a978396b2b3b279211819dee44618415aab1e99c2cb659 \
--hash=sha256:a3ea80aeb116d7978b26ac916d2a5a24d012b742bf28262b17769c4b886e8fba
# via
# aws-sam-cli (setup.py)
# cfn-lint
Expand Down Expand Up @@ -270,12 +270,7 @@ idna==3.4 \
importlib-metadata==6.7.0 \
--hash=sha256:1aaf550d4f73e5d6783e7acb77aec43d49da8017410afae93822cc9cca98c4d4 \
--hash=sha256:cb52082e659e97afc5dac71e79de97d8681de3aa07ff18578330904a9d18e5b5
# via
# attrs
# click
# flask
# jsonpickle
# jsonschema
# via flask
importlib-resources==5.12.0 \
--hash=sha256:4be82589bf5c1d7999aedf2a45159d10cb3ca4f19b2271f8792bc8e6da7b22f6 \
--hash=sha256:7b1deeebbf351c7578e09bf2f63fa2ce8b5ffec296e0d349139d43cca061a81a
Expand Down Expand Up @@ -722,12 +717,8 @@ typing-extensions==4.4.0 \
--hash=sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa \
--hash=sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e
# via
# arrow
# aws-sam-cli (setup.py)
# aws-sam-translator
# importlib-metadata
# jsonschema
# markdown-it-py
# pydantic
# rich
tzlocal==3.0 \
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__ = "1.89.0"
__version__ = "1.90.0"
23 changes: 23 additions & 0 deletions samcli/commands/_utils/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,29 @@ def use_container_build_option(f):
return use_container_build_click_option()(f)


def build_image_click_option(cls):
return click.option(
"--build-image",
"-bi",
default=None,
multiple=True, # Can pass in multiple build images
required=False,
help="Container image URIs for building functions/layers. "
"You can specify for all functions/layers with just the image URI "
"(--build-image public.ecr.aws/sam/build-nodejs18.x:latest). "
"You can specify for each individual function with "
"(--build-image FunctionLogicalID=public.ecr.aws/sam/build-nodejs18.x:latest). "
"A combination of the two can be used. If a function does not have build image specified or "
"an image URI for all functions, the default SAM CLI build images will be used.",
cls=cls,
)


@parameterized_option
def build_image_option(f, cls):
return build_image_click_option(cls)(f)


def _space_separated_list_func_type(value):
if isinstance(value, str):
return value.split(" ")
Expand Down
17 changes: 2 additions & 15 deletions samcli/commands/build/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
manifest_option,
cached_option,
use_container_build_option,
build_image_option,
hook_name_click_option,
)
from samcli.commands._utils.option_value_processor import process_env_var, process_image_options
Expand Down Expand Up @@ -94,21 +95,7 @@
help="Environment variables json file (e.g., env_vars.json) to be passed to build containers.",
cls=ContainerOptions,
)
@click.option(
"--build-image",
"-bi",
default=None,
multiple=True, # Can pass in multiple build images
required=False,
help="Container image URIs for building functions/layers. "
"You can specify for all functions/layers with just the image URI "
"(--build-image public.ecr.aws/sam/build-nodejs18.x:latest). "
"You can specify for each individual function with "
"(--build-image FunctionLogicalID=public.ecr.aws/sam/build-nodejs18.x:latest). "
"A combination of the two can be used. If a function does not have build image specified or "
"an image URI for all functions, the default SAM CLI build images will be used.",
cls=ContainerOptions,
)
@build_image_option(cls=ContainerOptions)
@click.option(
"--exclude",
"-x",
Expand Down
12 changes: 11 additions & 1 deletion samcli/commands/sync/command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""CLI command for "sync" command."""
import logging
import os
from typing import TYPE_CHECKING, List, Optional, Set
from typing import TYPE_CHECKING, List, Optional, Set, Tuple

import click

Expand All @@ -18,8 +18,10 @@
DEFAULT_CACHE_DIR,
)
from samcli.commands._utils.custom_options.replace_help_option import ReplaceHelpSummaryOption
from samcli.commands._utils.option_value_processor import process_image_options
from samcli.commands._utils.options import (
base_dir_option,
build_image_option,
capabilities_option,
image_repositories_option,
image_repository_option,
Expand All @@ -35,6 +37,7 @@
template_option_without_build,
use_container_build_option,
)
from samcli.commands.build.click_container import ContainerOptions
from samcli.commands.build.command import _get_mode_value_from_envvar
from samcli.commands.sync.core.command import SyncCommand
from samcli.commands.sync.sync_context import SyncContext
Expand Down Expand Up @@ -155,6 +158,7 @@
@stack_name_option(required=True) # pylint: disable=E1120
@base_dir_option
@use_container_build_option
@build_image_option(cls=ContainerOptions)
@image_repository_option
@image_repositories_option
@s3_bucket_option(disable_callback=True) # pylint: disable=E1120
Expand Down Expand Up @@ -202,6 +206,7 @@ def cli(
use_container: bool,
config_file: str,
config_env: str,
build_image: Optional[Tuple[str]],
) -> None:
"""
`sam sync` command entry point
Expand Down Expand Up @@ -234,6 +239,7 @@ def cli(
tags,
metadata,
use_container,
build_image,
config_file,
config_env,
None, # TODO: replace with build_in_source once it's added as a click option
Expand Down Expand Up @@ -265,6 +271,7 @@ def do_cli(
tags: dict,
metadata: dict,
use_container: bool,
build_image: Optional[Tuple[str]],
config_file: str,
config_env: str,
build_in_source: Optional[bool],
Expand Down Expand Up @@ -303,6 +310,8 @@ def do_cli(
LOG.debug("Using build directory as %s", build_dir)
EventTracker.track_event("UsedFeature", "Accelerate")

processed_build_images = process_image_options(build_image)

with BuildContext(
resource_identifier=None,
template_file=template_file,
Expand All @@ -320,6 +329,7 @@ def do_cli(
print_success_message=False,
locate_layer_nested=True,
build_in_source=build_in_source,
build_images=processed_build_images,
) as build_context:
built_template = os.path.join(build_dir, DEFAULT_TEMPLATE_NAME)

Expand Down
1 change: 1 addition & 0 deletions samcli/commands/sync/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"notification_arns",
"tags",
"metadata",
"build_image",
]

CONFIGURATION_OPTION_NAMES: List[str] = ["config_env", "config_file"]
Expand Down
4 changes: 4 additions & 0 deletions samcli/lib/build/bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

LOG = logging.getLogger(__name__)

LAYER_PREFIX = "/opt"
ESBUILD_PROPERTY = "esbuild"


Expand Down Expand Up @@ -157,6 +158,9 @@ def _should_update_handler(self, handler: str, name: str) -> bool:
if not handler_filename:
LOG.debug("Unable to parse handler, continuing without post-processing template.")
return False
if handler_filename.startswith(LAYER_PREFIX):
LOG.debug("Skipping updating the handler path as it is pointing to a layer.")
return False
expected_artifact_path = Path(self._build_dir, name, handler_filename)
return not expected_artifact_path.is_file()

Expand Down
27 changes: 27 additions & 0 deletions tests/end_to_end/test_runtimes_e2e.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from distutils.dir_util import copy_tree
from unittest import skipIf

import json
from pathlib import Path

import os
from parameterized import parameterized_class

from tests.end_to_end.end_to_end_base import EndToEndBase
Expand Down Expand Up @@ -163,3 +165,28 @@ def test_go_hello_world_default_workflow(self):
DefaultDeleteStage(BaseValidator(e2e_context), e2e_context, delete_command_list, stack_name),
]
self._run_tests(stages)


class TestEsbuildDatadogLayerIntegration(EndToEndBase):
app_template = ""

def test_integration(self):
function_name = "HelloWorldFunction"
event = '{"hello": "world"}'
stack_name = self._method_to_stack_name(self.id())
with EndToEndTestContext(self.app_name) as e2e_context:
project_path = str(Path("testdata") / "esbuild-datadog-integration")
os.mkdir(e2e_context.project_directory)
copy_tree(project_path, e2e_context.project_directory)
self.template_path = e2e_context.template_path
build_command_list = self.get_command_list()
deploy_command_list = self._get_deploy_command(stack_name)
remote_invoke_command_list = self._get_remote_invoke_command(stack_name, function_name, event, "json")
delete_command_list = self._get_delete_command(stack_name)
stages = [
EndToEndBaseStage(BuildValidator(e2e_context), e2e_context, build_command_list),
EndToEndBaseStage(BaseValidator(e2e_context), e2e_context, deploy_command_list),
EndToEndBaseStage(RemoteInvokeValidator(e2e_context), e2e_context, remote_invoke_command_list),
DefaultDeleteStage(BaseValidator(e2e_context), e2e_context, delete_command_list, stack_name),
]
self._run_tests(stages)
8 changes: 8 additions & 0 deletions tests/end_to_end/testdata/esbuild-datadog-integration/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exports.lambdaHandler = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({
message: 'hello world!',
}),
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31

# Latest extension version: https://github.com/DataDog/datadog-lambda-extension/releases
# Latest Node.js layer version: https://github.com/DataDog/datadog-lambda-js/releases

Parameters:
DataDogLayers:
Description: DataDog layers
Type: CommaDelimitedList
Default: "arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node18-x:93, arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Extension:44"

Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
Handler: /opt/nodejs/node_modules/datadog-lambda-js/handler.handler
Runtime: nodejs18.x
Environment:
Variables:
DD_LAMBDA_HANDLER: main.lambdaHandler
Layers: !Ref DataDogLayers
Metadata:
BuildMethod: esbuild
BuildProperties:
EntryPoints:
- main.js
1 change: 1 addition & 0 deletions tests/unit/commands/samconfig/test_samconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@ def test_sync(
{"a": "tag1", "b": "tag with spaces"},
{"m1": "value1", "m2": "value2"},
True,
(),
"samconfig.toml",
"default",
None,
Expand Down
Loading