Skip to content

Commit

Permalink
Merge from aws/aws-sam-cli/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-sam-cli-bot authored Feb 27, 2023
2 parents 916db74 + 35dbc95 commit e59d907
Show file tree
Hide file tree
Showing 47 changed files with 2,050 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/close-stale-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
permissions:
issues: write
steps:
- uses: aws-actions/stale-issue-cleanup@v3
- uses: aws-actions/stale-issue-cleanup@v6
with:
issue-types: issues

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/need-attention-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
apply-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v3
- uses: actions/github-script@v6
# the login of our bot called 'sam-cli-bot'
if: github.event.sender.login != 'aws-sam-cli-stale-bot'
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v3
- uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
apply-internal-external-label:
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v5
- uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ venv.*/
# mypy
.mypy_cache/

# ruff
.ruff_cache/

# SAM default build folder
.aws-sam/

### SublimeText ###
# cache files for sublime text
*.tmlanguage.cache
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jmespath~=0.10.0
ruamel_yaml==0.17.21
PyYAML>=5.4.1,==5.*
cookiecutter~=2.1.1
aws-sam-translator==1.59.0
aws-sam-translator==1.60.0
#docker minor version updates can include breaking changes. Auto update micro version only.
docker~=4.2.0
dateparser~=1.0
Expand Down
45 changes: 3 additions & 42 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.27.0 \
--hash=sha256:8019d5d5d7de32b159e33ff447672308fc20dd58bc7452f82af15f6667037e1f \
--hash=sha256:ca4374209755af250ae5c9b6e7c5a315ec39f41e7b901af050d242e1eaeedf27
# via aws-sam-cli (setup.py)
aws-sam-translator==1.59.0 \
--hash=sha256:6761293a21bd1cb0e19f168926ebfc4a3a6c9011aca67bd448ef485a55d6f658 \
--hash=sha256:9b8f23a5754cba92677d334ece5c5d9dc9b1f1a327a650fc8939ae3fc6da4141
aws-sam-translator==1.60.0 \
--hash=sha256:b104e327a8542cb966ca9e1ddf7f94d7821497d4c8c4a66ef0eb5e2ec4212af1 \
--hash=sha256:ba3c4e38c6dd2f7e530f71eec2012b491fb7cde934d0ff5db4145209995095dd
# via
# aws-sam-cli (setup.py)
# cfn-lint
Expand Down Expand Up @@ -304,44 +304,6 @@ pycparser==2.21 \
--hash=sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9 \
--hash=sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206
# via cffi
pydantic==1.10.4 \
--hash=sha256:05a81b006be15655b2a1bae5faa4280cf7c81d0e09fcb49b342ebf826abe5a72 \
--hash=sha256:0b53e1d41e97063d51a02821b80538053ee4608b9a181c1005441f1673c55423 \
--hash=sha256:2b3ce5f16deb45c472dde1a0ee05619298c864a20cded09c4edd820e1454129f \
--hash=sha256:2e82a6d37a95e0b1b42b82ab340ada3963aea1317fd7f888bb6b9dfbf4fff57c \
--hash=sha256:301d626a59edbe5dfb48fcae245896379a450d04baeed50ef40d8199f2733b06 \
--hash=sha256:39f4a73e5342b25c2959529f07f026ef58147249f9b7431e1ba8414a36761f53 \
--hash=sha256:4948f264678c703f3877d1c8877c4e3b2e12e549c57795107f08cf70c6ec7774 \
--hash=sha256:4b05697738e7d2040696b0a66d9f0a10bec0efa1883ca75ee9e55baf511909d6 \
--hash=sha256:51bdeb10d2db0f288e71d49c9cefa609bca271720ecd0c58009bd7504a0c464c \
--hash=sha256:55b1625899acd33229c4352ce0ae54038529b412bd51c4915349b49ca575258f \
--hash=sha256:572066051eeac73d23f95ba9a71349c42a3e05999d0ee1572b7860235b850cc6 \
--hash=sha256:6a05a9db1ef5be0fe63e988f9617ca2551013f55000289c671f71ec16f4985e3 \
--hash=sha256:6dc1cc241440ed7ca9ab59d9929075445da6b7c94ced281b3dd4cfe6c8cff817 \
--hash=sha256:6e7124d6855b2780611d9f5e1e145e86667eaa3bd9459192c8dc1a097f5e9903 \
--hash=sha256:75d52162fe6b2b55964fbb0af2ee58e99791a3138588c482572bb6087953113a \
--hash=sha256:78cec42b95dbb500a1f7120bdf95c401f6abb616bbe8785ef09887306792e66e \
--hash=sha256:7feb6a2d401f4d6863050f58325b8d99c1e56f4512d98b11ac64ad1751dc647d \
--hash=sha256:8775d4ef5e7299a2f4699501077a0defdaac5b6c4321173bcb0f3c496fbadf85 \
--hash=sha256:887ca463c3bc47103c123bc06919c86720e80e1214aab79e9b779cda0ff92a00 \
--hash=sha256:9193d4f4ee8feca58bc56c8306bcb820f5c7905fd919e0750acdeeeef0615b28 \
--hash=sha256:983e720704431a6573d626b00662eb78a07148c9115129f9b4351091ec95ecc3 \
--hash=sha256:990406d226dea0e8f25f643b370224771878142155b879784ce89f633541a024 \
--hash=sha256:9cbdc268a62d9a98c56e2452d6c41c0263d64a2009aac69246486f01b4f594c4 \
--hash=sha256:a48f1953c4a1d9bd0b5167ac50da9a79f6072c63c4cef4cf2a3736994903583e \
--hash=sha256:a9a6747cac06c2beb466064dda999a13176b23535e4c496c9d48e6406f92d42d \
--hash=sha256:a9f2de23bec87ff306aef658384b02aa7c32389766af3c5dee9ce33e80222dfa \
--hash=sha256:b5635de53e6686fe7a44b5cf25fcc419a0d5e5c1a1efe73d49d48fe7586db854 \
--hash=sha256:b6f9d649892a6f54a39ed56b8dfd5e08b5f3be5f893da430bed76975f3735d15 \
--hash=sha256:b9a3859f24eb4e097502a3be1fb4b2abb79b6103dd9e2e0edb70613a4459a648 \
--hash=sha256:cd8702c5142afda03dc2b1ee6bc358b62b3735b2cce53fc77b31ca9f728e4bc8 \
--hash=sha256:d7b5a3821225f5c43496c324b0d6875fde910a1c2933d726a743ce328fbb2a8c \
--hash=sha256:d88c4c0e5c5dfd05092a4b271282ef0588e5f4aaf345778056fc5259ba098857 \
--hash=sha256:eb992a1ef739cc7b543576337bebfc62c0e6567434e522e97291b251a41dad7f \
--hash=sha256:f2f7eb6273dd12472d7f218e1fef6f7c7c2f00ac2e1ecde4db8824c457300416 \
--hash=sha256:fdf88ab63c3ee282c76d652fc86518aacb737ff35796023fae56a65ced1a5978 \
--hash=sha256:fdf8d759ef326962b4678d89e275ffc55b7ce59d917d9f72233762061fd04a2d
# via aws-sam-translator
pyopenssl==23.0.0 \
--hash=sha256:c1cc5f86bcacefc84dada7d31175cae1b1518d5f60d3d0bb595a67822a868a6f \
--hash=sha256:df5fc28af899e74e19fccb5510df423581047e10ab6f1f4ba1763ff5fde844c0
Expand Down Expand Up @@ -527,7 +489,6 @@ typing-extensions==4.4.0 \
# aws-sam-cli (setup.py)
# aws-sam-translator
# importlib-metadata
# pydantic
tzlocal==3.0 \
--hash=sha256:c736f2540713deb5938d789ca7c3fc25391e9a20803f05b60ec64987cf086559 \
--hash=sha256:f4e6e36db50499e0d92f79b67361041f048e2609d166e93456b50746dc4aef12
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.74.0"
__version__ = "1.75.0"
6 changes: 4 additions & 2 deletions samcli/commands/_utils/table_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def pprint_wrap(func):
def wrap(*args, **kwargs):
# The table is setup with the column names, format_string contains the column names.
if table_header:
click.secho("\n" + table_header.format(args[0].client_sleep) if display_sleep else table_header)
click.secho(
"\n" + table_header.format(args[0].client_sleep) if display_sleep else table_header, bold=True
)
click.secho("-" * usable_width, fg=color)
click.secho(format_string.format(*format_args, **format_kwargs), fg=color)
click.secho("-" * usable_width, fg=color)
Expand All @@ -74,7 +76,7 @@ def wrap(*args, **kwargs):
kwargs["margin"] = margin if margin else min_margin
result = func(*args, **kwargs)
# Complete the table
click.secho("-" * usable_width, fg=color)
click.secho("-" * usable_width + "\n", fg=color)
return result

return wrap
Expand Down
4 changes: 2 additions & 2 deletions samcli/commands/deploy/guided_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def guided_prompts(self, parameter_override_keys):

click.echo("\n\tLooking for resources needed for deployment:")
s3_bucket = manage_stack(profile=self.profile, region=region)
click.echo(f"\t Managed S3 bucket: {s3_bucket}")
click.echo("\t A different default S3 bucket can be set in samconfig.toml")
click.secho(f"\n\tManaged S3 bucket: {s3_bucket}", bold=True)
click.echo("\tA different default S3 bucket can be set in samconfig.toml")

image_repositories = self.prompt_image_repository(
stack_name, stacks, self.image_repositories, region, s3_bucket, self.s3_prefix
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/deploy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def print_deploy_args(
click.echo(f"\tParameter overrides : {parameter_overrides_format_text}")
click.echo(f"\tSigning Profiles : {signing_profiles_format_text}")

click.secho("\nInitiating deployment\n=====================", fg="yellow")
click.secho("\nInitiating deployment\n=====================\n", fg="yellow")


def sanitize_parameter_overrides(parameter_overrides):
Expand Down
35 changes: 19 additions & 16 deletions samcli/commands/sync/sync_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def __init__(self, dependency_layer: bool, build_dir: str, cache_dir: str):
self._file_path = Path(build_dir).parent.joinpath(DEFAULT_SYNC_STATE_FILE_NAME)

def __enter__(self) -> "SyncContext":
self._read()
with _lock:
self._read()
LOG.debug(
"Entering sync context, previous state: %s, current state: %s", self._previous_state, self._current_state
)
Expand All @@ -153,7 +154,8 @@ def __enter__(self) -> "SyncContext":
return self

def __exit__(self, *args) -> None:
self._write()
with _lock:
self._write()

def update_resource_sync_state(self, resource_id: str, hash_value: str) -> None:
"""
Expand All @@ -167,9 +169,10 @@ def update_resource_sync_state(self, resource_id: str, hash_value: str) -> None:
hash_value: str
The logical ID identifier of the resource
"""
LOG.debug("Updating resource_sync_state for resource %s with hash %s", resource_id, hash_value)
self._current_state.update_resource_sync_state(resource_id, hash_value)
self._write()
with _lock:
LOG.debug("Updating resource_sync_state for resource %s with hash %s", resource_id, hash_value)
self._current_state.update_resource_sync_state(resource_id, hash_value)
self._write()

def get_resource_latest_sync_hash(self, resource_id: str) -> Optional[str]:
"""
Expand All @@ -186,19 +189,19 @@ def get_resource_latest_sync_hash(self, resource_id: str) -> Optional[str]:
Optional[str]
The hash of the resource stored in resource_sync_state if it exists
"""
resource_sync_state = self._current_state.resource_sync_states.get(resource_id)
if not resource_sync_state:
LOG.debug("No latest hash found for resource %s", resource_id)
return None
LOG.debug(
"Latest resource_sync_state hash %s found for resource %s", resource_id, resource_sync_state.hash_value
)
return resource_sync_state.hash_value
with _lock:
resource_sync_state = self._current_state.resource_sync_states.get(resource_id)
if not resource_sync_state:
LOG.debug("No latest hash found for resource %s", resource_id)
return None
LOG.debug(
"Latest resource_sync_state hash %s found for resource %s", resource_id, resource_sync_state.hash_value
)
return resource_sync_state.hash_value

def _write(self) -> None:
with _lock:
with open(self._file_path, "w+") as file:
file.write(tomlkit.dumps(_sync_state_to_toml_document(self._current_state)))
with open(self._file_path, "w+") as file:
file.write(tomlkit.dumps(_sync_state_to_toml_document(self._current_state)))

def _read(self) -> None:
try:
Expand Down
2 changes: 1 addition & 1 deletion samcli/lib/deploy/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def wait_for_changeset(self, changeset_id, stack_name):
:param changeset_id: ID or name of the changeset
:param stack_name: Stack name
"""
sys.stdout.write("\nWaiting for changeset to be created..\n")
sys.stdout.write("\n\nWaiting for changeset to be created..\n\n")
sys.stdout.flush()

# Wait for changeset to be created
Expand Down
5 changes: 3 additions & 2 deletions samcli/lib/init/default_samconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def __init__(self, path, package_type, project_name):
Default(writing_type=WritingType.Both, key="parallel", value=True, command=["build"]),
Default(writing_type=WritingType.Both, key="capabilities", value="CAPABILITY_IAM", command=["deploy"]),
Default(writing_type=WritingType.Both, key="confirm_changeset", value=True, command=["deploy"]),
Default(writing_type=WritingType.ZIP, key="resolve_s3", value=True, command=["package"]),
Default(writing_type=WritingType.ZIP, key="resolve_s3", value=True, command=["deploy"]),
# NOTE(sriram-mv): Template is still uploaded to s3 regardless of Package Type.
Default(writing_type=WritingType.Both, key="resolve_s3", value=True, command=["package"]),
Default(writing_type=WritingType.Both, key="resolve_s3", value=True, command=["deploy"]),
Default(writing_type=WritingType.Image, key="resolve_image_repos", value=True, command=["deploy"]),
Default(writing_type=WritingType.Both, key="watch", value=True, command=["sync"]),
Default(
Expand Down
3 changes: 2 additions & 1 deletion samcli/lib/package/s3_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ def on_progress(self, bytes_transferred, **kwargs):
self._seen_so_far += bytes_transferred
percentage = (self._seen_so_far / self._size) * 100 # noqa: PLR2004
sys.stderr.write(
"\rUploading to %s %s / %s (%.2f%%)" % (self._remote_path, self._seen_so_far, self._size, percentage)
"\r\tUploading to %s %s / %s (%.2f%%)"
% (self._remote_path, self._seen_so_far, self._size, percentage)
)
sys.stderr.flush()
if int(percentage) == 100: # noqa: PLR2004
Expand Down
32 changes: 20 additions & 12 deletions samcli/lib/sync/flows/image_function_sync_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from samcli.lib.providers.provider import Stack
from samcli.lib.sync.flows.function_sync_flow import FunctionSyncFlow, wait_for_function_update_complete
from samcli.lib.sync.sync_flow import ApiCallTypes, ResourceAPICall
from samcli.lib.utils.hash import str_checksum

if TYPE_CHECKING: # pragma: no cover
from samcli.commands.build.build_context import BuildContext
Expand All @@ -22,7 +21,7 @@


class ImageFunctionSyncFlow(FunctionSyncFlow):
_ecr_client: Any
_ecr_client: Optional[Any]
_docker_client: Optional[DockerClient]
_image_name: Optional[str]

Expand All @@ -34,7 +33,6 @@ def __init__(
sync_context: "SyncContext",
physical_id_mapping: Dict[str, str],
stacks: List[Stack],
docker_client: Optional[DockerClient] = None,
):
"""
Parameters
Expand All @@ -51,20 +49,23 @@ def __init__(
Physical ID Mapping
stacks : Optional[List[Stack]]
Stacks
docker_client : Optional[DockerClient]
Docker client to be used for building and uploading images.
Defaults to docker.from_env() if None is provided.
"""
super().__init__(function_identifier, build_context, deploy_context, sync_context, physical_id_mapping, stacks)
self._ecr_client = None
self._image_name = None
self._docker_client = docker_client
self._docker_client = None

def set_up(self) -> None:
super().set_up()
self._ecr_client = self._boto_client("ecr")
def _get_docker_client(self) -> DockerClient:
"""Lazy instantiates and returns the docker client"""
if not self._docker_client:
self._docker_client = docker.from_env()
return self._docker_client

def _get_ecr_client(self) -> Any:
"""Lazy instantiates and returns the boto3 ecr client"""
if not self._ecr_client:
self._ecr_client = self._boto_client("ecr")
return self._ecr_client

def gather_resources(self) -> None:
"""Build function image and save it in self._image_name"""
Expand All @@ -82,7 +83,14 @@ def gather_resources(self) -> None:
)
self._image_name = builder.build().artifacts.get(self._function_identifier)
if self._image_name:
self._local_sha = str_checksum(self._image_name)
self._local_sha = self._get_local_image_id(self._image_name)

def _get_local_image_id(self, image: str) -> Optional[str]:
"""Returns the local hash of the image"""
docker_img = self._get_docker_client().images.get(image)
if not docker_img or not docker_img.attrs.get("Id"):
return None
return str(docker_img.attrs.get("Id"))

def compare_remote(self) -> bool:
return False
Expand All @@ -108,7 +116,7 @@ def sync(self) -> None:
LOG.debug("%sGetting ECR Repo from Remote Function", self.log_prefix)
function_result = self._lambda_client.get_function(FunctionName=function_physical_id)
ecr_repo = function_result.get("Code", dict()).get("ImageUri", "").split(":")[0]
ecr_uploader = ECRUploader(self._docker_client, self._ecr_client, ecr_repo, None)
ecr_uploader = ECRUploader(self._get_docker_client(), self._get_ecr_client(), ecr_repo, None)
image_uri = ecr_uploader.upload(self._image_name, self._function_identifier)

with ExitStack() as exit_stack:
Expand Down
Loading

0 comments on commit e59d907

Please sign in to comment.