目录
Harold Sun

fix(terraform-hook): improve Makefile generation (#9271)

  • fix(terraform-hook): prevent shell command injection in Makefile generation

The Terraform hook’s Makefile generator interpolated an untrusted Terraform resource address into a shell command string, escaping only the double-quote character. Backticks and $(…) were not escaped, allowing an attacker-controlled Terraform resource address (via a crafted for_each key or tampered plan file) to execute arbitrary commands on the build host during ‘sam build –hook-name terraform’.

Replace the double-quote-only escaping with shlex.quote(), after first escaping make’s own macroexpansion(macro expansion ( -> $), since make processes the recipe line before handing it to the shell.

Also reject resource addresses containing embedded newlines or carriage returns: make parses Makefiles line-by-line before shelling out, so shlex.quote() alone cannot neutralize an embedded newline, which could otherwise split one recipe line into multiple physical lines in the generated Makefile.

  • style: fix black formatting in terraform hook test file

  • fix: address PR review comments on injection fix

  • Escape all non-printable characters (not just \n/\r) in the error message preview for rejected resource addresses, so an attacker who triggers the newline-rejection path cannot also smuggle ANSI escape sequences or other control bytes into unfiltered stderr output.

  • Fix the shell-injection regression test to work reliably on Windows CI: skip it on Windows (it depends on /bin/sh and POSIX /tmp semantics that don’t translate cleanly to MSYS/Git-Bash path handling), and use a per-test unique marker path via tempfile.TemporaryDirectory() instead of a hardcoded /tmp path.

  • fix: keep untrusted Terraform values off the Makefile shell command line

Address PR review feedback: shlex.quote() only produces POSIX-safe quoting, but the Terraform hook is also supported on Windows, where GNU make falls back to cmd.exe as SHELL when sh.exe is not found on PATH. cmd.exe does not treat single quotes as quoting characters, so the previous fix broke every recipe (–expression always contains ‘|’, which cmd.exe interprets as a pipe outside of quotes).

Rather than trying to find an escaping scheme that is simultaneously safe for make’s macro expansion and portable across both shells, write the untrusted expression/resource address to a small JSON ‘args file’ in the SAM-CLI-controlled output directory, and pass only that file’s path (never user data) on the Makefile recipe’s command line. copy_terraform_built_artifacts.py reads –target/–expression from this file via a new –args-file option, falling back to the existing –target/–expression flags for backward compatibility.

This removes the need for shell/make escaping entirely for these values, since they never reach a shell or make’s macro expansion - only the JSON parser in copy_terraform_built_artifacts.py. It also addresses two test-quality issues flagged in review: the injection test using ‘&&’ after an always-failing preceding command (vacuous pass), and no coverage distinguishing escaped from unescaped ‘handling(mootnow,since' handling (moot now, since '‘ is no longer special-cased).

Removed InvalidTerraformResourceAddressException and its newline rejection logic, since embedded newlines are handled safely by JSON encoding and no longer risk splitting a Makefile recipe line.

sim: https://t.corp.amazon.com/P475859948

  • fix: sort imports to satisfy ruff I001 (make pr lint failure)

sim: https://t.corp.amazon.com/P475859948

  • fix: address further PR review comments on args-file handling
  • Guard the –args-file read in copy_terraform_built_artifacts.py against OSError/ValueError (missing/unreadable/corrupt file) and a non-object JSON top level, converting them into this script’s existing error-reporting convention (LOG.error + cli_exit()) rather than letting them surface as an uncaught traceback wrapped in a generic make failure

  • Use a deterministic args file name (logical_id.args.json) instead of appending uuid4(), since logical_id is already unique per resource and never attacker-influenced. sam build always re-runs prepare, so the uuid-based name caused a new file to accumulate on every build with nothing to clean them up; the deterministic name is overwritten each run instead

  • Added tests for both: deterministic-name/overwrite behavior in test_makefile_generator.py, and clean-error-on-bad-args-file in test_copy_terraform_built_artifacts.py

sim: https://t.corp.amazon.com/P475859948

  • fix: create output_dir before writing args file, add contract tests
  • _write_makerule_args_file() could run before generate_makefile() has a chance to create output_dir, since the prepare-hook contract does not guarantee the directory pre-exists (hook.py’s prepare() creates it itself rather than assuming a caller did). Call os.makedirs(…, exist_ok=True) before opening the args file for writing.

  • Added test_write_makerule_args_file_creates_output_dir_if_missing to cover this directly (previous tests masked it by always pre-creating output_dir).

  • Added test_script_output_path_directory_args_file, a positive integration test proving a valid –args-file actually supplies expression/target to the script end-to-end, so a producer/consumer key mismatch would be caught (previous new tests only covered failure paths: missing/malformed args file).

sim: https://t.corp.amazon.com/P475859948

  • fix: bound args file name to avoid exceeding filename length limits

build_cfn_logical_id() can produce a logical_id up to 255 characters (247 human-readable + 8 hash chars). Appending ‘.args.json’ (10 chars) to that could push the args file name past the 255-byte per-component limit enforced by most filesystems (ext4/xfs/btrfs/APFS) and Windows, causing open() to raise OSError for deeply-nested Lambda resources with long Terraform addresses.

Truncate logical_id to 236 characters and append an 8-char checksum of the full logical_id before the suffix, keeping the name at 254 bytes worst case while still being deterministic and disambiguating logical IDs that happen to share the same truncated prefix.

Also removed unused Path/skipIf imports left over from an earlier revision of the injection regression tests.

sim: https://t.corp.amazon.com/P475859948

  • fix: truncate args file name on UTF-8 bytes, not characters

logical_id is Unicode-aware (build_cfn_logical_id() keeps any Unicode alphanumeric character, not just ASCII), so a logical_id built from a non-ASCII for_each key (e.g. CJK) can be up to 255 characters while each character is multiple bytes in UTF-8. Truncating on character count let the encoded file name exceed the 255-byte per-component filesystem/OS limit that the truncation was meant to enforce.

Truncate on the UTF-8 encoded bytes instead (decoding back with errors=’ignore’ to drop any partial trailing multi-byte character), so the byte length bound holds regardless of script. The checksum is still computed over the full, untruncated logical_id.

Also corrected the docstring’s claim that logical_id is never

  • fix: name args files by hash and defer all writes to generate_makefile

Two review findings, addressed together since the second builds on the first:

  1. The args file name ({truncated_logical_id}{checksum}.args.json) guarded against the 255-byte per-component filesystem/OS filename limit, but not Windows’ 260-character MAX_PATH limit on the total path once combined with a real project directory path - which a deeply-nested Terraform module address can hit well before the per-component limit. Switched to a pure 16-char hash of logical_id (str_checksum(logical_id)[:16]}.args.json, 26 characters total), which sidesteps both limits regardless of how long or non-ASCII logical_id is. This also let us delete the byte-vs-character truncation logic and its three dedicated tests.

  2. _build_makerule_python_command had become a function with a filesystem side effect (creating the args file) called once per resource inside enrich_resources_and_generate_makefile‘s loop. If a later resource in that loop raised (e.g. an unrecognized sam metadata resource type), earlier resources’ args files were already on disk with no Makefile ever produced to go with them - orphaned files with nothing to clean them up. Made _build_makerule_python_command (and generate_makefile_rule_for_lambda_resource above it) pure again: they now return a PendingArgsFile (path, expression, target) instead of writing it. All args files are written in a single place

    • generate_makefile() - only after every rule in the batch has been generated successfully. generate_makefile() also now prunes any stale *.args.json left behind by a previous run (e.g. for a renamed or removed Lambda resource) before writing the current set, so nothing accumulates indefinitely either.

Testing:

  • Updated unit tests in test_makefile_generator.py for the new pure function signatures; added test_get_args_file_path_keeps_file_name_short_regardless_of_logical_id and test_generate_makefile_prunes_stale_args_files_and_writes_new_ones
  • Added test_enrich_resources_and_generate_makefile_does_not_write_anything_when_a_later_resource_fails to test_enrich.py, which does NOT mock generate_makefile_rule_for_lambda_resource so it genuinely exercises the pure-function contract, and asserts generate_makefile is never called when a later resource fails
  • 406/406 tests passing across tests/unit/hook_packages/terraform/ and tests/integration/scripts/test_copy_terraform_built_artifacts.py
  • ruff check samcli schema and black –check clean
  • Verified end-to-end with a real sam build --hook-name terraform run seeded with a stale args file using the old naming scheme: confirmed it is pruned and replaced with a new 16-char-hash-named file
  • fix: fix Windows CI failures from the previous commit

Two issues surfaced by make pr on windows-latest CI, both introduced by the previous commit:

  1. test_build_makerule_python_command compared PendingArgsFile.path (a native-OS-style absolute path, backslash-separated on Windows) against a value built with os.path.join(terraform_application_dir, args_file_relative_path), where args_file_relative_path was parsed out of the recipe text and is always unix-style (forward-slash), since the recipe is handed to a shell that may be cmd.exe. On Windows, os.path.join only inserts a backslash between the two arguments - it doesn’t normalize slashes already present inside args_file_relative_path - producing a mixed-separator path that never equals PendingArgsFile.path. Fixed by converting PendingArgsFile.path the same way _build_makerule_python_command itself does (relative_to + convert_path_to_unix_path) and comparing that to the recipe’s value, rather than trying to reconstruct the native path via string joining.

  2. Pruning stale args files via glob.glob(os.path.join(output_directory_path, “*.args.json”)) applies fnmatch pattern semantics to every path component, not just the final one. A project path containing a glob metacharacter ([, ], *, ?) makes the pattern silently match nothing, so pruning does not fail loudly - it just never removes anything, which is the exact accumulation problem pruning was added to prevent. Replaced glob with os.listdir + suffix filtering, which has no pattern-expansion semantics on the directory path at all. Added test_generate_makefile_prunes_stale_args_files_in_a_directory_with_glob_metacharacters to cover the case neither existing test could reach (mocked test asserts on a literal string; the other uses a tempfile.TemporaryDirectory path, which never contains metacharacters).

Testing:

  • 407/407 tests passing across tests/unit/hook_packages/terraform/ and tests/integration/scripts/test_copy_terraform_built_artifacts.py
  • ruff check samcli schema and black –check clean
  • Verified the glob bug empirically before fixing: glob.glob against a path containing “proj[1]” returned [] despite the file existing (confirmed via os.listdir), and returned the file once wrapped in glob.escape()

Co-authored-by: Chengjun Li licjun@amazon.com

2天前4348次提交
#x27; handling (moot now, since '
#x27; is no longer special-cased). Removed InvalidTerraformResourceAddressException and its newline rejection logic, since embedded newlines are handled safely by JSON encoding and no longer risk splitting a Makefile recipe line. sim: https://t.corp.amazon.com/P475859948 * fix: sort imports to satisfy ruff I001 (make pr lint failure) sim: https://t.corp.amazon.com/P475859948 * fix: address further PR review comments on args-file handling - Guard the --args-file read in copy_terraform_built_artifacts.py against OSError/ValueError (missing/unreadable/corrupt file) and a non-object JSON top level, converting them into this script's existing error-reporting convention (LOG.error + cli_exit()) rather than letting them surface as an uncaught traceback wrapped in a generic make failure - Use a deterministic args file name (logical_id.args.json) instead of appending uuid4(), since logical_id is already unique per resource and never attacker-influenced. sam build always re-runs prepare, so the uuid-based name caused a new file to accumulate on every build with nothing to clean them up; the deterministic name is overwritten each run instead - Added tests for both: deterministic-name/overwrite behavior in test_makefile_generator.py, and clean-error-on-bad-args-file in test_copy_terraform_built_artifacts.py sim: https://t.corp.amazon.com/P475859948 * fix: create output_dir before writing args file, add contract tests - _write_makerule_args_file() could run before generate_makefile() has a chance to create output_dir, since the prepare-hook contract does not guarantee the directory pre-exists (hook.py's prepare() creates it itself rather than assuming a caller did). Call os.makedirs(..., exist_ok=True) before opening the args file for writing. - Added test_write_makerule_args_file_creates_output_dir_if_missing to cover this directly (previous tests masked it by always pre-creating output_dir). - Added test_script_output_path_directory_args_file, a positive integration test proving a valid --args-file actually supplies expression/target to the script end-to-end, so a producer/consumer key mismatch would be caught (previous new tests only covered failure paths: missing/malformed args file). sim: https://t.corp.amazon.com/P475859948 * fix: bound args file name to avoid exceeding filename length limits build_cfn_logical_id() can produce a logical_id up to 255 characters (247 human-readable + 8 hash chars). Appending '.args.json' (10 chars) to that could push the args file name past the 255-byte per-component limit enforced by most filesystems (ext4/xfs/btrfs/APFS) and Windows, causing open() to raise OSError for deeply-nested Lambda resources with long Terraform addresses. Truncate logical_id to 236 characters and append an 8-char checksum of the full logical_id before the suffix, keeping the name at 254 bytes worst case while still being deterministic and disambiguating logical IDs that happen to share the same truncated prefix. Also removed unused Path/skipIf imports left over from an earlier revision of the injection regression tests. sim: https://t.corp.amazon.com/P475859948 * fix: truncate args file name on UTF-8 bytes, not characters logical_id is Unicode-aware (build_cfn_logical_id() keeps any Unicode alphanumeric character, not just ASCII), so a logical_id built from a non-ASCII for_each key (e.g. CJK) can be up to 255 characters while each character is multiple bytes in UTF-8. Truncating on character count let the encoded file name exceed the 255-byte per-component filesystem/OS limit that the truncation was meant to enforce. Truncate on the UTF-8 encoded bytes instead (decoding back with errors='ignore' to drop any partial trailing multi-byte character), so the byte length bound holds regardless of script. The checksum is still computed over the full, untruncated logical_id. Also corrected the docstring's claim that logical_id is never * fix: name args files by hash and defer all writes to generate_makefile Two review findings, addressed together since the second builds on the first: 1. The args file name (`{truncated_logical_id}{checksum}.args.json`) guarded against the 255-byte per-component filesystem/OS filename limit, but not Windows' 260-character MAX_PATH limit on the *total* path once combined with a real project directory path - which a deeply-nested Terraform module address can hit well before the per-component limit. Switched to a pure 16-char hash of logical_id (`str_checksum(logical_id)[:16]}.args.json`, 26 characters total), which sidesteps both limits regardless of how long or non-ASCII logical_id is. This also let us delete the byte-vs-character truncation logic and its three dedicated tests. 2. `_build_makerule_python_command` had become a function with a filesystem side effect (creating the args file) called once per resource inside `enrich_resources_and_generate_makefile`'s loop. If a *later* resource in that loop raised (e.g. an unrecognized sam metadata resource type), earlier resources' args files were already on disk with no Makefile ever produced to go with them - orphaned files with nothing to clean them up. Made `_build_makerule_python_command` (and `generate_makefile_rule_for_lambda_resource` above it) pure again: they now return a `PendingArgsFile` (path, expression, target) instead of writing it. All args files are written in a single place - `generate_makefile()` - only after every rule in the batch has been generated successfully. `generate_makefile()` also now prunes any stale `*.args.json` left behind by a previous run (e.g. for a renamed or removed Lambda resource) before writing the current set, so nothing accumulates indefinitely either. Testing: - Updated unit tests in test_makefile_generator.py for the new pure function signatures; added test_get_args_file_path_keeps_file_name_short_regardless_of_logical_id and test_generate_makefile_prunes_stale_args_files_and_writes_new_ones - Added test_enrich_resources_and_generate_makefile_does_not_write_anything_when_a_later_resource_fails to test_enrich.py, which does NOT mock generate_makefile_rule_for_lambda_resource so it genuinely exercises the pure-function contract, and asserts generate_makefile is never called when a later resource fails - 406/406 tests passing across tests/unit/hook_packages/terraform/ and tests/integration/scripts/test_copy_terraform_built_artifacts.py - ruff check samcli schema and black --check clean - Verified end-to-end with a real `sam build --hook-name terraform` run seeded with a stale args file using the old naming scheme: confirmed it is pruned and replaced with a new 16-char-hash-named file * fix: fix Windows CI failures from the previous commit Two issues surfaced by `make pr` on windows-latest CI, both introduced by the previous commit: 1. test_build_makerule_python_command compared PendingArgsFile.path (a native-OS-style absolute path, backslash-separated on Windows) against a value built with os.path.join(terraform_application_dir, args_file_relative_path), where args_file_relative_path was parsed out of the recipe text and is always unix-style (forward-slash), since the recipe is handed to a shell that may be cmd.exe. On Windows, os.path.join only inserts a backslash between the two arguments - it doesn't normalize slashes already present inside args_file_relative_path - producing a mixed-separator path that never equals PendingArgsFile.path. Fixed by converting PendingArgsFile.path the same way _build_makerule_python_command itself does (relative_to + convert_path_to_unix_path) and comparing that to the recipe's value, rather than trying to reconstruct the native path via string joining. 2. Pruning stale args files via glob.glob(os.path.join(output_directory_path, "*.args.json")) applies fnmatch pattern semantics to every path component, not just the final one. A project path containing a glob metacharacter (`[`, `]`, `*`, `?`) makes the pattern silently match nothing, so pruning does not fail loudly - it just never removes anything, which is the exact accumulation problem pruning was added to prevent. Replaced glob with os.listdir + suffix filtering, which has no pattern-expansion semantics on the directory path at all. Added test_generate_makefile_prunes_stale_args_files_in_a_directory_with_glob_metacharacters to cover the case neither existing test could reach (mocked test asserts on a literal string; the other uses a tempfile.TemporaryDirectory path, which never contains metacharacters). Testing: - 407/407 tests passing across tests/unit/hook_packages/terraform/ and tests/integration/scripts/test_copy_terraform_built_artifacts.py - ruff check samcli schema and black --check clean - Verified the glob bug empirically before fixing: glob.glob against a path containing "proj[1]" returned [] despite the file existing (confirmed via os.listdir), and returned the file once wrapped in glob.escape() --------- Co-authored-by: Chengjun Li <licjun@amazon.com>" href="/mirrors/aws-sam-cli/commits/5b20d0ec50">fix(terraform-hook): improve Makefile generation (#9271)
2天前
  • schemafeat: sam init output json (#9176)18天前
  • tests
  • #x27; handling (moot now, since '
    #x27; is no longer special-cased). Removed InvalidTerraformResourceAddressException and its newline rejection logic, since embedded newlines are handled safely by JSON encoding and no longer risk splitting a Makefile recipe line. sim: https://t.corp.amazon.com/P475859948 * fix: sort imports to satisfy ruff I001 (make pr lint failure) sim: https://t.corp.amazon.com/P475859948 * fix: address further PR review comments on args-file handling - Guard the --args-file read in copy_terraform_built_artifacts.py against OSError/ValueError (missing/unreadable/corrupt file) and a non-object JSON top level, converting them into this script's existing error-reporting convention (LOG.error + cli_exit()) rather than letting them surface as an uncaught traceback wrapped in a generic make failure - Use a deterministic args file name (logical_id.args.json) instead of appending uuid4(), since logical_id is already unique per resource and never attacker-influenced. sam build always re-runs prepare, so the uuid-based name caused a new file to accumulate on every build with nothing to clean them up; the deterministic name is overwritten each run instead - Added tests for both: deterministic-name/overwrite behavior in test_makefile_generator.py, and clean-error-on-bad-args-file in test_copy_terraform_built_artifacts.py sim: https://t.corp.amazon.com/P475859948 * fix: create output_dir before writing args file, add contract tests - _write_makerule_args_file() could run before generate_makefile() has a chance to create output_dir, since the prepare-hook contract does not guarantee the directory pre-exists (hook.py's prepare() creates it itself rather than assuming a caller did). Call os.makedirs(..., exist_ok=True) before opening the args file for writing. - Added test_write_makerule_args_file_creates_output_dir_if_missing to cover this directly (previous tests masked it by always pre-creating output_dir). - Added test_script_output_path_directory_args_file, a positive integration test proving a valid --args-file actually supplies expression/target to the script end-to-end, so a producer/consumer key mismatch would be caught (previous new tests only covered failure paths: missing/malformed args file). sim: https://t.corp.amazon.com/P475859948 * fix: bound args file name to avoid exceeding filename length limits build_cfn_logical_id() can produce a logical_id up to 255 characters (247 human-readable + 8 hash chars). Appending '.args.json' (10 chars) to that could push the args file name past the 255-byte per-component limit enforced by most filesystems (ext4/xfs/btrfs/APFS) and Windows, causing open() to raise OSError for deeply-nested Lambda resources with long Terraform addresses. Truncate logical_id to 236 characters and append an 8-char checksum of the full logical_id before the suffix, keeping the name at 254 bytes worst case while still being deterministic and disambiguating logical IDs that happen to share the same truncated prefix. Also removed unused Path/skipIf imports left over from an earlier revision of the injection regression tests. sim: https://t.corp.amazon.com/P475859948 * fix: truncate args file name on UTF-8 bytes, not characters logical_id is Unicode-aware (build_cfn_logical_id() keeps any Unicode alphanumeric character, not just ASCII), so a logical_id built from a non-ASCII for_each key (e.g. CJK) can be up to 255 characters while each character is multiple bytes in UTF-8. Truncating on character count let the encoded file name exceed the 255-byte per-component filesystem/OS limit that the truncation was meant to enforce. Truncate on the UTF-8 encoded bytes instead (decoding back with errors='ignore' to drop any partial trailing multi-byte character), so the byte length bound holds regardless of script. The checksum is still computed over the full, untruncated logical_id. Also corrected the docstring's claim that logical_id is never * fix: name args files by hash and defer all writes to generate_makefile Two review findings, addressed together since the second builds on the first: 1. The args file name (`{truncated_logical_id}{checksum}.args.json`) guarded against the 255-byte per-component filesystem/OS filename limit, but not Windows' 260-character MAX_PATH limit on the *total* path once combined with a real project directory path - which a deeply-nested Terraform module address can hit well before the per-component limit. Switched to a pure 16-char hash of logical_id (`str_checksum(logical_id)[:16]}.args.json`, 26 characters total), which sidesteps both limits regardless of how long or non-ASCII logical_id is. This also let us delete the byte-vs-character truncation logic and its three dedicated tests. 2. `_build_makerule_python_command` had become a function with a filesystem side effect (creating the args file) called once per resource inside `enrich_resources_and_generate_makefile`'s loop. If a *later* resource in that loop raised (e.g. an unrecognized sam metadata resource type), earlier resources' args files were already on disk with no Makefile ever produced to go with them - orphaned files with nothing to clean them up. Made `_build_makerule_python_command` (and `generate_makefile_rule_for_lambda_resource` above it) pure again: they now return a `PendingArgsFile` (path, expression, target) instead of writing it. All args files are written in a single place - `generate_makefile()` - only after every rule in the batch has been generated successfully. `generate_makefile()` also now prunes any stale `*.args.json` left behind by a previous run (e.g. for a renamed or removed Lambda resource) before writing the current set, so nothing accumulates indefinitely either. Testing: - Updated unit tests in test_makefile_generator.py for the new pure function signatures; added test_get_args_file_path_keeps_file_name_short_regardless_of_logical_id and test_generate_makefile_prunes_stale_args_files_and_writes_new_ones - Added test_enrich_resources_and_generate_makefile_does_not_write_anything_when_a_later_resource_fails to test_enrich.py, which does NOT mock generate_makefile_rule_for_lambda_resource so it genuinely exercises the pure-function contract, and asserts generate_makefile is never called when a later resource fails - 406/406 tests passing across tests/unit/hook_packages/terraform/ and tests/integration/scripts/test_copy_terraform_built_artifacts.py - ruff check samcli schema and black --check clean - Verified end-to-end with a real `sam build --hook-name terraform` run seeded with a stale args file using the old naming scheme: confirmed it is pruned and replaced with a new 16-char-hash-named file * fix: fix Windows CI failures from the previous commit Two issues surfaced by `make pr` on windows-latest CI, both introduced by the previous commit: 1. test_build_makerule_python_command compared PendingArgsFile.path (a native-OS-style absolute path, backslash-separated on Windows) against a value built with os.path.join(terraform_application_dir, args_file_relative_path), where args_file_relative_path was parsed out of the recipe text and is always unix-style (forward-slash), since the recipe is handed to a shell that may be cmd.exe. On Windows, os.path.join only inserts a backslash between the two arguments - it doesn't normalize slashes already present inside args_file_relative_path - producing a mixed-separator path that never equals PendingArgsFile.path. Fixed by converting PendingArgsFile.path the same way _build_makerule_python_command itself does (relative_to + convert_path_to_unix_path) and comparing that to the recipe's value, rather than trying to reconstruct the native path via string joining. 2. Pruning stale args files via glob.glob(os.path.join(output_directory_path, "*.args.json")) applies fnmatch pattern semantics to every path component, not just the final one. A project path containing a glob metacharacter (`[`, `]`, `*`, `?`) makes the pattern silently match nothing, so pruning does not fail loudly - it just never removes anything, which is the exact accumulation problem pruning was added to prevent. Replaced glob with os.listdir + suffix filtering, which has no pattern-expansion semantics on the directory path at all. Added test_generate_makefile_prunes_stale_args_files_in_a_directory_with_glob_metacharacters to cover the case neither existing test could reach (mocked test asserts on a literal string; the other uses a tempfile.TemporaryDirectory path, which never contains metacharacters). Testing: - 407/407 tests passing across tests/unit/hook_packages/terraform/ and tests/integration/scripts/test_copy_terraform_built_artifacts.py - ruff check samcli schema and black --check clean - Verified the glob bug empirically before fixing: glob.glob against a path containing "proj[1]" returned [] despite the file existing (confirmed via os.listdir), and returned the file once wrapped in glob.escape() --------- Co-authored-by: Chengjun Li <licjun@amazon.com>" href="/mirrors/aws-sam-cli/commits/5b20d0ec50">fix(terraform-hook): improve Makefile generation (#9271)
    2天前
  • .coveragercfeat: Terraform support (#4373)3年前
  • .coveragerc_no_lang_extfeat: Add CloudFormation Language Extensions support (Fn::ForEach) (#8637)4个月前
  • .gitignorefix(unzip): replace UserException with ValueError exception in `_extract()` (#8599)8个月前
  • .gitpod.DockerfileMatdumsa/gitpod setup (#2039)6年前
  • .gitpod.ymlMatdumsa/gitpod setup (#2039)6年前
  • .pre-commit-config.yamlchore: Manage black version in dev.txt (#2314)5年前
  • CODEOWNERSchore: remove SBT team from CODEOWNERS (#8024)1年前
  • CODE_OF_CONDUCT.mdAdding standard files (#335)8年前
  • CONTRIBUTING.mddocs: align contributor Python version docs with package metadata (#9047)4个月前
  • DESIGN.mdfeat: Telemetry Implementation (#1287)7年前
  • DEVELOPMENT_GUIDE.mddocs: align contributor Python version docs with package metadata (#9047)4个月前
  • LICENSEfix: Update copyright in LICENSE (#1295)7年前
  • MANIFEST.inchore: migrate dependencies to pyproject.toml and drop Python 3.9 support (#8747)6个月前
  • Make.ps1chore: fix typos in Make.ps1 comments (#9145)1个月前
  • Makefilefeat: Add CloudFormation Language Extensions support (Fn::ForEach) (#8637)4个月前
  • NOTICEfeat: MacOS PyInstaller build spec and update on licenses (#4442)3年前
  • README.mdfix(README): correct the dead link on open source contribution story (#8283)12个月前
  • THIRD-PARTY-LICENSESchore(deps): bump idna from 2.10 to 3.4 in /requirements (#4770)3年前
  • appveyor-linux-binary.ymlchore: update version of Maven used in tests (#8806)6个月前
  • appveyor-ubuntu.ymlchore: update version of Maven used in tests (#8806)6个月前
  • appveyor-windows-al2023.ymlfix: set maven path in al2023 tests (#8640)7个月前
  • appveyor-windows-binary.ymlchore: migrate dependencies to pyproject.toml and drop Python 3.9 support (#8747)6个月前
  • appveyor-windows.ymlfix: install maven in windows tests (#8639)7个月前
  • mypy.inichore(deps): bump cfn-lint from 0.87.7 to 1.4.2 in /requirements (#7207)2年前
  • pyproject.tomlfix(validate): pin cfn-lint below the release that drops the SAM transform (#9249)9天前
  • pytest.iniSplit long-running integ tests to stay under 10 min (#8887)5个月前
  • setup.pychore: migrate dependencies to pyproject.toml and drop Python 3.9 support (#8747)6个月前
  • AWS SAM CLI

    Apache 2.0 License SAM CLI Version Install pip

    Installation | Blogs | Videos | AWS Docs | Roadmap | Try It Out | Slack Us

    The AWS Serverless Application Model (SAM) CLI is an open-source CLI tool that helps you develop serverless applications containing Lambda functions, Step Functions, API Gateway, EventBridge, SQS, SNS and more. Some of the features it provides are:

    • Initialize serverless applications in minutes with AWS-provided infrastructure templates with sam init
    • Compile, build, and package Lambda functions with provided runtimes and with custom Makefile workflows, for zip and image types of Lambda functions with sam build
    • Locally test a Lambda function and API Gateway easily in a Docker container with sam local commands on SAM and CDK applications
    • Sync and test your changes in the cloud with sam sync in your developer environments
    • Deploy your SAM and CloudFormation templates using sam deploy
    • Quickly create pipelines with prebuilt templates with popular CI/CD systems using sam pipeline init
    • Tail CloudWatch logs and X-Ray traces with sam logs and sam traces

    Recent blogposts and workshops

    • Speeding up incremental changes with AWS SAM Accelerate and Nested Stacks - Read blogpost here.

    • Develop Node projects with SAM CLI using esbuild - and use SAM Accelerate on Typescript projects. Read blogpost here.

    • Speed up development with SAM Accelerate - quickly test your changes in the cloud. Read docs here.

    • AWS Serverless Developer Experience Workshop: A day in a life of a developer - This advanced workshop provides you with an immersive experience as a serverless developer, with hands-on experience building a serverless solution using AWS SAM and SAM CLI.

    • The Complete SAM Workshop - This workshop is a great way to experience the power of SAM and SAM CLI.

    • Getting started with CI/CD? SAM pipelines can help you get started - This workshop walks you through the basics.

    • Get started with Serverless Application development using SAM CLI - This workshop walks you through the basics.

    Get Started

    To get started with building SAM-based applications, use the SAM CLI. SAM CLI provides a Lambda-like execution environment that lets you locally build, test, debug, and deploy AWS serverless applications.

    Next Steps: Learn to build a more complex serverless application.

    What is this Github repository? 💻

    This Github repository contains source code for SAM CLI. Here is the development team talking about this code:

    SAM CLI code is written in Python. Source code is well documented, very modular, with 95% unit test coverage. It uses this awesome Python library called Click to manage the command line interaction and uses Docker to run Lambda functions locally. We think you’ll like the code base. Clone it and run make pr or ./Make -pr on Windows!

    Contribute to SAM

    We love our contributors ❤️ We have over 100 contributors who have built various parts of the product. Read this testimonial from @ndobryanskyy to learn more about what it was like contributing to SAM.

    Depending on your interest and skill, you can help build the different parts of the SAM project;

    Enhance the SAM Specification

    Make pull requests, report bugs, and share ideas to improve the full SAM template specification. Source code is located on Github at aws/serverless-application-model. Read the SAM Specification Contributing Guide to get started.

    Strengthen SAM CLI

    Add new commands, enhance existing ones, report bugs, or request new features for the SAM CLI. Source code is located on Github at aws/aws-sam-cli. Read the SAM CLI Contributing Guide to get started.

    Update SAM Developer Guide

    SAM Developer Guide provides a comprehensive getting started guide and reference documentation. Source code is located on Github at awsdocs/aws-sam-developer-guide. Read the SAM Documentation Contribution Guide to get started.

    Join the SAM Community on Slack

    Join the SAM developers channel (#samdev) on Slack to collaborate with fellow community members and the AWS SAM team.

    邀请码
      Gitlink(确实开源)
    • 加入我们
    • 官网邮箱:gitlink@ccf.org.cn
    • QQ群
    • QQ群
    • 公众号
    • 公众号

    版权所有:中国计算机学会技术支持:开源发展技术委员会
    京ICP备13000930号-9 京公网安备 11010802047560号