Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d506648
chore: Increase awareness of same file warning during package (#2946)
mndeveci Jun 24, 2021
698de67
fix: Allow the base64Encoded field in REST Api, skip validation of un…
moelasmar Jun 24, 2021
3b2cdf1
fix: pass copy of environment variables for keeping cache valid (#2943)
mndeveci Jun 29, 2021
6fc1b99
fix: Skip build of Docker image if ImageUri is a valid ECR URL (#2934…
alexisfacques Jun 29, 2021
0d58f89
Add condition to managed bucket policy (#2999)
qingchm Jun 30, 2021
50ac3cb
Update appveyor.yml to do docker login on both dockerhub and Public E…
qingchm Jul 1, 2021
f1e0569
chore: bump version to 1.25.0 (#3007)
qingchm Jul 1, 2021
2241563
temp: reduce python testing matrix (#3008)
sriram-mv Jul 1, 2021
fe83218
temp: disable testing against python 3.8, and enabled 3.7 (#3009)
moelasmar Jul 1, 2021
cc806a2
fix: enable all runtimes in python testing matrix (#3011)
qingchm Jul 1, 2021
ac4e485
chore: update to aws-sam-translator 1.37.0 (#3019)
mgrandis Jul 6, 2021
a1e5c92
chore: bump version to 1.26.0 (#3020)
mgrandis Jul 6, 2021
59c8576
chore: Improved --resolve-s3 option documentation and deployment with…
qingchm Jul 8, 2021
0626f94
feat: Add SAM Pipeline commands (#3085)
aahung Jul 20, 2021
ecd02bb
chore: bump aws-lambda-builder version to 1.5.0 (#3086)
wchengru Jul 20, 2021
3fda4c5
chore: update to aws-sam-translator 1.38.0 (#3073)
c2tarun Jul 20, 2021
6b7ec4f
ci: Update expected Jenkins file in pipeline integ test (#3090)
aahung Jul 20, 2021
9206b47
chore: Refine pipeline help text and update unit test (#3091)
aahung Jul 21, 2021
aae1e97
Clearing pipeline integ test buckets with versioned objects. (#3094)
c2tarun Jul 21, 2021
8bbb7c5
Fixing bug in bucket cleanup. (#3096)
c2tarun Jul 21, 2021
172616c
Deleting bucket (#3097)
c2tarun Jul 21, 2021
1916bfa
Revert "temp: disable testing against python 3.8, and enabled 3.7 (#3…
c2tarun Jul 21, 2021
50ef124
chore: bump SAM CLI version to 1.27.0 (#3101)
wchengru Jul 21, 2021
1c42df3
Add pipeline to pyinstaller (#3103)
c2tarun Jul 21, 2021
d707abe
Merge branch 'develop' into feat/sam_delete
moelasmar Jul 22, 2021
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
8 changes: 6 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ for:
# Pre-dev Tests
- "pip install -e \".[pre-dev]\""
- "pylint --rcfile .pylintrc samcli"

# Dev Tests
- "pip install -e \".[dev]\""
- "pytest --cov samcli --cov-report term-missing --cov-fail-under 94 tests/unit"
Expand All @@ -170,7 +170,11 @@ for:
# Runs only in Linux, logging docker hub when running canary and docker cred is available
- sh: "
if [[ -n $BY_CANARY ]] && [[ -n $DOCKER_USER ]] && [[ -n $DOCKER_PASS ]];
then echo Logging in Docker Hub; echo $DOCKER_PASS | docker login --username $DOCKER_USER --password-stdin;
then echo Logging in Docker Hub; echo $DOCKER_PASS | docker login --username $DOCKER_USER --password-stdin registry-1.docker.io;
fi"
- sh: "
if [[ -n $BY_CANARY ]];
then echo Logging in Public ECR; aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws;
fi"
- sh: "pytest -vv tests/integration"
- sh: "pytest -vv tests/regression"
Expand Down
10 changes: 5 additions & 5 deletions requirements/reproducible-linux.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile
# This file is autogenerated by pip-compile with python 3.7
# To update, run:
#
# pip-compile --allow-unsafe --generate-hashes --output-file=requirements/reproducible-linux.txt
Expand Down Expand Up @@ -88,17 +88,17 @@ itsdangerous==1.1.0 \
--hash=sha256:321b033d07f2a4136d3ec762eac9f16a10ccd60f53c0c91af90217ace7ba1f19 \
--hash=sha256:b12271b2047cb23eeb98c8b5622e2e5c5e9abd9784a153e9d8ef9cb4dd09d749
# via flask
jinja2-time==0.2.0 \
--hash=sha256:d14eaa4d315e7688daa4969f616f226614350c48730bfa1692d2caebd8c90d40 \
--hash=sha256:d3eab6605e3ec8b7a0863df09cc1d23714908fa61aa6986a845c20ba488b4efa
# via cookiecutter
jinja2==2.11.3 \
--hash=sha256:03e47ad063331dd6a3f04a43eddca8a966a26ba0c5b7207a9a9e4e08f1b29419 \
--hash=sha256:a6d58433de0ae800347cab1fa3043cebbabe8baa9d29e668f1c768cb87a333c6
# via
# cookiecutter
# flask
# jinja2-time
jinja2-time==0.2.0 \
--hash=sha256:d14eaa4d315e7688daa4969f616f226614350c48730bfa1692d2caebd8c90d40 \
--hash=sha256:d3eab6605e3ec8b7a0863df09cc1d23714908fa61aa6986a845c20ba488b4efa
# via cookiecutter
jmespath==0.10.0 \
--hash=sha256:b85d0567b8666149a93172712e68920734333c0ce7e89b78b3e987f71e5ed4f9 \
--hash=sha256:cdf6525904cc597730141d61b36f2e4b8ecc257c420fa2f4549bac2c2d0cb72f
Expand Down
4 changes: 3 additions & 1 deletion samcli/commands/deploy/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@
"--resolve-s3",
required=False,
is_flag=True,
help="Automatically resolve s3 bucket for non-guided deployments."
help="Automatically resolve s3 bucket for non-guided deployments. "
"Enabling this option will also create a managed default s3 bucket for you. "
"If you do not provide a --s3-bucket value, the managed bucket will be used. "
"Do not use --s3-guided parameter with this option.",
)
@metadata_override_option
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/deploy/guided_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def prompt_image_repository(self, stacks: List[Stack]):
if isinstance(self.image_repositories, dict)
else "" or self.image_repository,
)
if not is_ecr_url(image_repositories.get(resource_id)):
if resource_id not in image_repositories or not is_ecr_url(str(image_repositories[resource_id])):
raise GuidedDeployFailedError(
f"Invalid Image Repository ECR URI: {image_repositories.get(resource_id)}"
)
Expand Down
4 changes: 3 additions & 1 deletion samcli/commands/package/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def resources_and_properties_help_string():
exc_set=PackageResolveS3AndS3SetError,
exc_not_set=PackageResolveS3AndS3NotSetError,
),
help="Automatically resolve s3 bucket for non-guided deployments."
help="Automatically resolve s3 bucket for non-guided deployments. "
"Enabling this option will also create a managed default s3 bucket for you. "
"If you do not provide a --s3-bucket value, the managed bucket will be used. "
"Do not use --s3-guided parameter with this option.",
)
@metadata_override_option
Expand Down
3 changes: 2 additions & 1 deletion samcli/commands/package/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ class BucketNotSpecifiedError(UserException):
def __init__(self, **kwargs):
self.kwargs = kwargs

message_fmt = "\nS3 Bucket not specified, use --s3-bucket to specify a bucket name or run sam deploy --guided"
message_fmt = "\nS3 Bucket not specified, use --s3-bucket to specify a bucket name, or use --resolve-s3 \
to create a managed default bucket, or run sam deploy --guided"

super().__init__(message=message_fmt.format(**self.kwargs))

Expand Down
3 changes: 3 additions & 0 deletions samcli/lib/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def _get_stack_template():
- "/*"
Principal:
Service: serverlessrepo.amazonaws.com
Condition:
StringEquals:
aws:SourceAccount: !Ref AWS::AccountId

Outputs:
SourceBucket:
Expand Down
7 changes: 6 additions & 1 deletion samcli/lib/build/build_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pathlib
import shutil
from abc import abstractmethod, ABC
from copy import deepcopy
from typing import Callable, Dict, List, Any, Optional, cast

from samcli.commands.build.exceptions import MissingBuildMethodException
Expand Down Expand Up @@ -114,6 +115,10 @@ def build_single_function_definition(self, build_definition: FunctionBuildDefini

LOG.debug("Building to following folder %s", single_build_dir)

# we should create a copy and pass it down, otherwise additional env vars like LAMBDA_BUILDERS_LOG_LEVEL
# will make cache invalid all the time
container_env_vars = deepcopy(build_definition.env_vars)

# when a function is passed here, it is ZIP function, codeuri and runtime are not None
result = self._build_function(
build_definition.get_function_name(),
Expand All @@ -123,7 +128,7 @@ def build_single_function_definition(self, build_definition: FunctionBuildDefini
build_definition.get_handler_name(),
single_build_dir,
build_definition.metadata,
build_definition.env_vars,
container_env_vars,
)
function_build_results[single_full_path] = result

Expand Down
2 changes: 1 addition & 1 deletion samcli/lib/package/ecr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
from samcli.lib.package.regexpr import ECR_URL


def is_ecr_url(url):
def is_ecr_url(url: str) -> bool:
return bool(re.match(ECR_URL, url)) if url else False
28 changes: 28 additions & 0 deletions samcli/lib/providers/sam_base_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from samcli.lib.intrinsic_resolver.intrinsics_symbol_table import IntrinsicsSymbolTable
from samcli.lib.samlib.resource_metadata_normalizer import ResourceMetadataNormalizer
from samcli.lib.samlib.wrapper import SamTranslatorWrapper
from samcli.lib.package.ecr_utils import is_ecr_url


LOG = logging.getLogger(__name__)

Expand All @@ -34,6 +36,11 @@ class SamBaseProvider:
SERVERLESS_LAYER: "ContentUri",
}

IMAGE_PROPERTY_KEYS = {
LAMBDA_FUNCTION: "Code",
SERVERLESS_FUNCTION: "ImageUri",
}

def get(self, name: str) -> Optional[Any]:
"""
Given name of the function, this method must return the Function object
Expand Down Expand Up @@ -88,6 +95,17 @@ def _is_s3_location(location: Optional[Union[str, Dict]]) -> bool:
isinstance(location, str) and location.startswith("s3://")
)

@staticmethod
def _is_ecr_uri(location: Optional[Union[str, Dict]]) -> bool:
"""
the input could be:
- ImageUri of Serverless::Function
- Code of Lambda::Function
"""
return location is not None and is_ecr_url(
str(location.get("ImageUri", "")) if isinstance(location, dict) else location
)

@staticmethod
def _warn_code_extraction(resource_type: str, resource_name: str, code_property: str) -> None:
LOG.warning(
Expand All @@ -98,6 +116,16 @@ def _warn_code_extraction(resource_type: str, resource_name: str, code_property:
code_property,
)

@staticmethod
def _warn_imageuri_extraction(resource_type: str, resource_name: str, image_property: str) -> None:
LOG.warning(
"The resource %s '%s' has specified ECR registry image for %s. "
"It will not be built and SAM CLI does not support invoking it locally.",
resource_type,
resource_name,
image_property,
)

@staticmethod
def _extract_lambda_function_imageuri(resource_properties: Dict, code_property_key: str) -> Optional[str]:
"""
Expand Down
17 changes: 16 additions & 1 deletion samcli/lib/providers/sam_function_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,28 @@ def _extract_functions(
resource_properties["Metadata"] = resource_metadata

if resource_type in [SamFunctionProvider.SERVERLESS_FUNCTION, SamFunctionProvider.LAMBDA_FUNCTION]:
resource_package_type = resource_properties.get("PackageType", ZIP)

code_property_key = SamBaseProvider.CODE_PROPERTY_KEYS[resource_type]
if SamBaseProvider._is_s3_location(resource_properties.get(code_property_key)):
image_property_key = SamBaseProvider.IMAGE_PROPERTY_KEYS[resource_type]

if resource_package_type == ZIP and SamBaseProvider._is_s3_location(
resource_properties.get(code_property_key)
):

# CodeUri can be a dictionary of S3 Bucket/Key or a S3 URI, neither of which are supported
if not ignore_code_extraction_warnings:
SamFunctionProvider._warn_code_extraction(resource_type, name, code_property_key)
continue

if resource_package_type == IMAGE and SamBaseProvider._is_ecr_uri(
resource_properties.get(image_property_key)
):
# ImageUri can be an ECR uri, which is not supported
if not ignore_code_extraction_warnings:
SamFunctionProvider._warn_imageuri_extraction(resource_type, name, image_property_key)
continue

if resource_type == SamFunctionProvider.SERVERLESS_FUNCTION:
layers = SamFunctionProvider._parse_layer_info(
stack,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Resources:
MQFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: s3://sam-demo-bucket/queues.zip
Handler: queue.mq_handler
Runtime: python2.7
Events:
MyMQQueue:
Type: MQ
Properties:
Broker: arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
Queues:
- "Queue1"
SourceAccessConfigurations:
- Type: BASIC_AUTH
URI: arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c
- Type: VIRTUAL_HOST
URI: vhost_name
30 changes: 30 additions & 0 deletions tests/integration/buildcmd/test_build_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,36 @@ def test_cache_build(self, use_container, code_uri, function1_handler, function2
expected_messages, command_result, self._make_parameter_override_arg(overrides)
)

@skipIf(SKIP_DOCKER_TESTS, SKIP_DOCKER_MESSAGE)
def test_cached_build_with_env_vars(self):
"""
Build 2 times to verify that second time hits the cached build
"""
overrides = {
"FunctionCodeUri": "Python",
"Function1Handler": "main.first_function_handler",
"Function2Handler": "main.second_function_handler",
"FunctionRuntime": "python3.8",
}
cmdlist = self.get_command_list(
use_container=True, parameter_overrides=overrides, cached=True, container_env_var="FOO=BAR"
)

LOG.info("Running Command (cache should be invalid): %s", cmdlist)
command_result = run_command(cmdlist, cwd=self.working_dir)
self.assertTrue(
"Cache is invalid, running build and copying resources to function build definition"
in command_result.stderr.decode("utf-8")
)

LOG.info("Re-Running Command (valid cache should exist): %s", cmdlist)
command_result_with_cache = run_command(cmdlist, cwd=self.working_dir)

self.assertTrue(
"Valid cache found, copying previously built resources from function build definition"
in command_result_with_cache.stderr.decode("utf-8")
)


@skipIf(
((IS_WINDOWS and RUNNING_ON_CI) and not CI_OVERRIDE),
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/deploy/test_deploy_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ def test_deploy_without_s3_bucket(self, template_file):
self.assertEqual(deploy_process_execute.process.returncode, 1)
self.assertIn(
bytes(
f"S3 Bucket not specified, use --s3-bucket to specify a bucket name or run sam deploy --guided",
f"S3 Bucket not specified, use --s3-bucket to specify a bucket name, or use --resolve-s3 \
to create a managed default bucket, or run sam deploy --guided",
encoding="utf-8",
),
deploy_process_execute.stderr,
Expand Down
Loading