aws-lambda-builders 1.65.0__tar.gz → 1.66.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. {aws_lambda_builders-1.65.0/aws_lambda_builders.egg-info → aws_lambda_builders-1.66.0}/PKG-INFO +1 -1
  2. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/__init__.py +1 -1
  3. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/dotnet_clipackage/actions.py +22 -1
  4. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py +1 -1
  5. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/rust_cargo/DESIGN.md +6 -0
  6. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/rust_cargo/actions.py +41 -3
  7. aws_lambda_builders-1.66.0/aws_lambda_builders/workflows/rust_cargo/cargo_lambda.py +261 -0
  8. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/rust_cargo/workflow.py +1 -1
  9. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0/aws_lambda_builders.egg-info}/PKG-INFO +1 -1
  10. aws_lambda_builders-1.65.0/aws_lambda_builders/workflows/rust_cargo/cargo_lambda.py +0 -137
  11. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/LICENSE +0 -0
  12. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/MANIFEST.in +0 -0
  13. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/NOTICE +0 -0
  14. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/README.md +0 -0
  15. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/__main__.py +0 -0
  16. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/actions.py +0 -0
  17. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/architecture.py +0 -0
  18. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/binary_path.py +0 -0
  19. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/builder.py +0 -0
  20. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/exceptions.py +0 -0
  21. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/path_resolver.py +0 -0
  22. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/registry.py +0 -0
  23. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/supported_runtimes.py +0 -0
  24. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/utils.py +0 -0
  25. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/validator.py +0 -0
  26. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflow.py +0 -0
  27. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/__init__.py +0 -0
  28. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/custom_make/DESIGN.md +0 -0
  29. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/custom_make/__init__.py +0 -0
  30. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/custom_make/actions.py +0 -0
  31. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/custom_make/exceptions.py +0 -0
  32. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/custom_make/make.py +0 -0
  33. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/custom_make/utils.py +0 -0
  34. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/custom_make/validator.py +0 -0
  35. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/custom_make/workflow.py +0 -0
  36. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/dotnet_clipackage/DESIGN.md +0 -0
  37. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/dotnet_clipackage/__init__.py +0 -0
  38. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py +0 -0
  39. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli_resolver.py +0 -0
  40. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/dotnet_clipackage/utils.py +0 -0
  41. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/go_modules/DESIGN.md +0 -0
  42. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/go_modules/__init__.py +0 -0
  43. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/go_modules/actions.py +0 -0
  44. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/go_modules/builder.py +0 -0
  45. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/go_modules/utils.py +0 -0
  46. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/go_modules/validator.py +0 -0
  47. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/go_modules/workflow.py +0 -0
  48. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java/__init__.py +0 -0
  49. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java/actions.py +0 -0
  50. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java/utils.py +0 -0
  51. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_gradle/DESIGN.md +0 -0
  52. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_gradle/__init__.py +0 -0
  53. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_gradle/actions.py +0 -0
  54. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_gradle/gradle.py +0 -0
  55. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_gradle/gradle_resolver.py +0 -0
  56. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_gradle/gradle_validator.py +0 -0
  57. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_gradle/resources/lambda-build-init.gradle +0 -0
  58. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_gradle/workflow.py +0 -0
  59. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_maven/DESIGN.md +0 -0
  60. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_maven/__init__.py +0 -0
  61. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_maven/actions.py +0 -0
  62. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_maven/maven.py +0 -0
  63. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_maven/maven_resolver.py +0 -0
  64. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_maven/maven_validator.py +0 -0
  65. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/java_maven/workflow.py +0 -0
  66. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm/DESIGN.md +0 -0
  67. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm/__init__.py +0 -0
  68. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm/actions.py +0 -0
  69. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm/exceptions.py +0 -0
  70. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm/npm.py +0 -0
  71. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm/utils.py +0 -0
  72. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm/workflow.py +0 -0
  73. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm_esbuild/DESIGN.md +0 -0
  74. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm_esbuild/__init__.py +0 -0
  75. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm_esbuild/actions.py +0 -0
  76. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm_esbuild/esbuild.py +0 -0
  77. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm_esbuild/exceptions.py +0 -0
  78. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/nodejs_npm_esbuild/workflow.py +0 -0
  79. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_pip/DESIGN.md +0 -0
  80. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_pip/__init__.py +0 -0
  81. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_pip/actions.py +0 -0
  82. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_pip/compat.py +0 -0
  83. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_pip/exceptions.py +0 -0
  84. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_pip/packager.py +0 -0
  85. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_pip/utils.py +0 -0
  86. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_pip/validator.py +0 -0
  87. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_pip/workflow.py +0 -0
  88. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_uv/DESIGN.md +0 -0
  89. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_uv/__init__.py +0 -0
  90. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_uv/actions.py +0 -0
  91. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_uv/exceptions.py +0 -0
  92. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_uv/packager.py +0 -0
  93. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_uv/utils.py +0 -0
  94. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/python_uv/workflow.py +0 -0
  95. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/ruby_bundler/DESIGN.md +0 -0
  96. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/ruby_bundler/__init__.py +0 -0
  97. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/ruby_bundler/actions.py +0 -0
  98. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/ruby_bundler/bundler.py +0 -0
  99. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/ruby_bundler/utils.py +0 -0
  100. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/ruby_bundler/workflow.py +0 -0
  101. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/rust_cargo/__init__.py +0 -0
  102. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/rust_cargo/exceptions.py +0 -0
  103. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders/workflows/rust_cargo/utils.py +0 -0
  104. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders.egg-info/SOURCES.txt +0 -0
  105. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders.egg-info/dependency_links.txt +0 -0
  106. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders.egg-info/entry_points.txt +0 -0
  107. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders.egg-info/requires.txt +0 -0
  108. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/aws_lambda_builders.egg-info/top_level.txt +0 -0
  109. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/pyproject.toml +0 -0
  110. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/requirements/base.txt +0 -0
  111. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/requirements/dev.txt +0 -0
  112. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/requirements/python_pip.txt +0 -0
  113. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/setup.cfg +0 -0
  114. {aws_lambda_builders-1.65.0 → aws_lambda_builders-1.66.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aws_lambda_builders
3
- Version: 1.65.0
3
+ Version: 1.66.0
4
4
  Summary: Python library to compile, build & package AWS Lambda functions for several runtimes & frameworks.
5
5
  Home-page: https://github.com/awslabs/aws-lambda-builders
6
6
  Author: Amazon Web Services
@@ -5,5 +5,5 @@ AWS Lambda Builder Library
5
5
  # Changing version will trigger a new release!
6
6
  # Please make the version change as the last step of your development.
7
7
 
8
- __version__ = "1.65.0"
8
+ __version__ = "1.66.0"
9
9
  RPC_PROTOCOL_VERSION = "0.3"
@@ -28,9 +28,21 @@ class GlobalToolInstallAction(BaseAction):
28
28
  DESCRIPTION = "Install or update the Amazon.Lambda.Tools .NET Core Global Tool."
29
29
  PURPOSE = Purpose.COMPILE_SOURCE
30
30
 
31
- def __init__(self, subprocess_dotnet):
31
+ def __init__(self, subprocess_dotnet, runtime=None):
32
32
  super(GlobalToolInstallAction, self).__init__()
33
33
  self.subprocess_dotnet = subprocess_dotnet
34
+ self.runtime = runtime
35
+
36
+ def _existing_tool_available(self):
37
+ """
38
+ Returns True if a working Amazon.Lambda.Tools is already available on the PATH
39
+ (e.g. pre-installed in the SAM build image).
40
+ """
41
+ try:
42
+ self.subprocess_dotnet.run(["lambda", "help"])
43
+ return True
44
+ except DotnetCLIExecutionError:
45
+ return False
34
46
 
35
47
  def execute(self):
36
48
  # run Amazon.Lambda.Tools update in sync block in case build is triggered in parallel
@@ -42,6 +54,15 @@ class GlobalToolInstallAction(BaseAction):
42
54
  LOG.info("Skipping to update Amazon.Lambda.Tools install/update, since it is updated recently")
43
55
  return
44
56
 
57
+ # Amazon.Lambda.Tools 7.0.0 dropped support for dotnet6 (EOL runtime), so
58
+ # installing/updating to latest breaks dotnet6 builds. If a working tool is
59
+ # already available (e.g. pre-installed in the SAM build image), use it as is.
60
+ # Deliberately not setting __tools_installed here so other runtimes in the
61
+ # same process still install/update to latest as before.
62
+ if self.runtime == "dotnet6" and self._existing_tool_available():
63
+ LOG.info("Skipping Amazon.Lambda.Tools install/update for dotnet6; using the pre-installed version")
64
+ return
65
+
45
66
  try:
46
67
  LOG.debug("Installing Amazon.Lambda.Tools Global Tool")
47
68
  self.subprocess_dotnet.run(["tool", "install", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"])
@@ -29,7 +29,7 @@ class DotnetCliPackageWorkflow(BaseWorkflow):
29
29
 
30
30
  options = kwargs["options"] if "options" in kwargs else {}
31
31
  subprocess_dotnetcli = SubprocessDotnetCLI(os_utils=OSUtils())
32
- dotnetcli_install = GlobalToolInstallAction(subprocess_dotnet=subprocess_dotnetcli)
32
+ dotnetcli_install = GlobalToolInstallAction(subprocess_dotnet=subprocess_dotnetcli, runtime=runtime)
33
33
 
34
34
  dotnetcli_deployment = RunPackageAction(
35
35
  source_dir,
@@ -16,10 +16,16 @@ The general algorithm for preparing a rust executable for use on AWS Lambda is a
16
16
 
17
17
  It builds a binary in the standard cargo target directory. The binary's name is always `bootstrap`, and it's always located under `target/lambda/HANDLER_NAME/bootstrap`.
18
18
 
19
+ For a Cargo workspace, the build targets the workspace's shared `target` directory rather than a `target` directory under each member. Because `sam build` invokes this workflow once per function, sharing a single target directory lets cargo compile common dependencies once instead of recompiling the whole dependency tree for every function. The shared directory and the member's binary name are both read from a single `cargo metadata` call. For a standalone (non-workspace) project the shared `target` directory is the project's own — unchanged from prior behavior. An explicit `CARGO_TARGET_DIR` in the environment always takes precedence.
20
+
19
21
  ### Copy and Rename executable
20
22
 
21
23
  It then copies the executable to the target directory honoring the provided runtime's [expectation on executable names](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html).
22
24
 
25
+ Because every workspace member now builds into the same `target/lambda` directory, that directory holds all of the workspace's binaries. When no handler (`artifact_executable_name`) is given, the copy step selects the binary named for the package whose manifest lives in the function's source directory (from the same `cargo metadata` call). It falls back to the previous single-directory heuristic when the binary name cannot be resolved.
26
+
27
+ If two or more workspace members define a `bin` target with the same name (for example each package declaring a `bootstrap` bin), those binaries compile to the same path in the shared directory and overwrite each other. `sam build` still produces correct artifacts because it copies each function's binary out immediately after building it, but this relies on build ordering, so the workflow logs a warning recommending unique bin names per function.
28
+
23
29
  ## Notes
24
30
 
25
31
  Like the go builders, the workflow argument `options.artifact_executable_name`
@@ -104,7 +104,9 @@ class RustCopyAndRenameAction(BaseAction):
104
104
  DESCRIPTION = "Copy Rust executable, renaming if needed"
105
105
  PURPOSE = Purpose.COPY_SOURCE
106
106
 
107
- def __init__(self, source_dir, artifacts_dir, handler=None, osutils=OSUtils()):
107
+ def __init__(
108
+ self, source_dir, artifacts_dir, handler=None, binaries=None, subprocess_cargo_lambda=None, osutils=OSUtils()
109
+ ):
108
110
  """
109
111
  Copy and rename Rust executable
110
112
 
@@ -119,21 +121,57 @@ class RustCopyAndRenameAction(BaseAction):
119
121
  handler : str, optional
120
122
  Handler name in `package.bin_name` or `bin_name` format
121
123
 
124
+ binaries : dict, optional
125
+ Resolved path dependencies, used to locate the `cargo` binary when
126
+ resolving the workspace target directory
127
+
128
+ subprocess_cargo_lambda : aws_lambda_builders.workflows.rust_cargo.cargo_lambda.SubprocessCargoLambda, optional
129
+ The Cargo Lambda process wrapper, used to resolve the same target
130
+ directory the build action compiled into
131
+
122
132
  osutils : aws_lambda_builders.workflows.rust_cargo.utils.OSUtils, optional
123
133
  Optional, External IO utils
124
134
  """
125
135
  self._source_dir = source_dir
126
136
  self._handler = handler
127
137
  self._artifacts_dir = artifacts_dir
138
+ self._binaries = binaries
139
+ self._subprocess_cargo_lambda = subprocess_cargo_lambda
128
140
  self._osutils = osutils
129
141
 
142
+ def _workspace_layout(self):
143
+ # Resolve the same shared target directory and binary name the build action
144
+ # used, from a single cached cargo metadata call. Returns None when the
145
+ # cargo wrapper is unavailable (e.g. in unit tests exercising the legacy path).
146
+ if self._subprocess_cargo_lambda and self._binaries and self._binaries.get("cargo"):
147
+ return self._subprocess_cargo_lambda.resolve_workspace_layout(
148
+ self._binaries["cargo"].binary_path, self._source_dir
149
+ )
150
+ return None
151
+
130
152
  def base_path(self):
153
+ # For a workspace member this is the workspace root's shared target/lambda; for
154
+ # a standalone project it is source_dir/target/lambda, matching the legacy path.
155
+ layout = self._workspace_layout()
156
+ if layout and layout.get("target_directory"):
157
+ return os.path.join(layout["target_directory"], "lambda")
131
158
  return os.path.join(self._source_dir, "target", "lambda")
132
159
 
133
160
  def binary_path(self):
134
161
  base = self.base_path()
135
- if self._handler:
136
- binary_path = os.path.join(base, self._handler, "bootstrap")
162
+
163
+ # An explicit handler (artifact_executable_name) always wins.
164
+ binary_name = self._handler
165
+ # Otherwise use the bin name cargo reported for this member. This is what lets
166
+ # the copy step pick the right binary now that every member shares one
167
+ # target/lambda directory holding all of the workspace's binaries.
168
+ if not binary_name:
169
+ layout = self._workspace_layout()
170
+ if layout:
171
+ binary_name = layout.get("binary_name")
172
+
173
+ if binary_name:
174
+ binary_path = os.path.join(base, binary_name, "bootstrap")
137
175
  LOG.debug("copying function binary from %s", binary_path)
138
176
  return binary_path
139
177
 
@@ -0,0 +1,261 @@
1
+ """
2
+ Wrapper around calling Cargo Lambda through a subprocess.
3
+ """
4
+
5
+ import io
6
+ import json
7
+ import logging
8
+ import os
9
+ import shutil
10
+ import subprocess
11
+ import threading
12
+
13
+ from .exceptions import CargoLambdaExecutionException
14
+ from .utils import OSUtils
15
+
16
+ LOG = logging.getLogger(__name__)
17
+
18
+
19
+ class SubprocessCargoLambda(object):
20
+ """
21
+ Wrapper around the Cargo Lambda command line utility, making it
22
+ easy to consume execution results.
23
+ """
24
+
25
+ def __init__(self, which, executable_search_paths=None, osutils=OSUtils()):
26
+ """
27
+ Parameters
28
+ ----------
29
+ which : aws_lambda_builders.utils.which
30
+ Function to get paths which conform to the given mode on the PATH
31
+ with the prepended additional search paths
32
+
33
+ executable_search_paths : list, optional
34
+ List of paths to the NPM package binary utilities. This will
35
+ be used to find embedded esbuild at runtime if present in the package
36
+
37
+ osutils : aws_lambda_builders.workflows.rust_cargo.utils.OSUtils, optional
38
+ An instance of OS Utilities for file manipulation
39
+ """
40
+ self._which = which
41
+ self._executable_search_paths = executable_search_paths
42
+ self._osutils = osutils
43
+ self._workspace_layout_cache = {}
44
+
45
+ def check_cargo_lambda_installation(self):
46
+ """
47
+ Checks if Cargo Lambda is in the system
48
+
49
+ Returns
50
+ -------
51
+ str
52
+ Path to the cargo-lambda binary
53
+
54
+ Raises
55
+ ------
56
+ CargoLambdaExecutionException:
57
+ Raised when Cargo Lambda is not installed in the system to run the command.
58
+ """
59
+
60
+ LOG.debug("checking for cargo-lambda")
61
+ binaries = self._which("cargo-lambda", executable_search_paths=self._executable_search_paths)
62
+ LOG.debug("potential cargo-lambda binaries: %s", binaries)
63
+
64
+ if binaries:
65
+ return binaries[0]
66
+ else:
67
+ raise CargoLambdaExecutionException(
68
+ message="Cannot find Cargo Lambda. "
69
+ "Cargo Lambda must be installed on the host machine to use this feature. "
70
+ "Follow the gettings started guide to learn how to install it: "
71
+ "https://www.cargo-lambda.info/guide/getting-started.html"
72
+ )
73
+
74
+ def resolve_workspace_layout(self, cargo_path, source_dir):
75
+ """
76
+ Resolves the Cargo target directory and the binary produced for ``source_dir``.
77
+
78
+ A single ``cargo metadata`` call yields both:
79
+
80
+ - ``target_directory`` is the workspace's shared ``target`` directory.
81
+ For a Cargo workspace member this is the workspace root's ``target``,
82
+ which cargo shares across every member. Building each function into
83
+ that shared directory lets cargo reuse compiled dependencies across
84
+ the separate per-function builds that ``sam build`` runs, instead of
85
+ recompiling the whole dependency tree once per function. For a
86
+ standalone project it is the project's own ``target`` -- the location
87
+ used before this change.
88
+
89
+ - ``binary_name`` is the name of the ``bin`` target defined by the
90
+ package whose manifest lives in ``source_dir``. Because every member
91
+ now builds into the same ``target/lambda`` directory, the copy step
92
+ can no longer assume that directory holds a single binary; this name
93
+ tells it which one belongs to the function being built.
94
+
95
+ Results are cached per ``source_dir``.
96
+
97
+ Parameters
98
+ ----------
99
+ cargo_path : str
100
+ Path to the ``cargo`` binary.
101
+
102
+ source_dir : str
103
+ Path to the folder containing the function's source code.
104
+
105
+ Returns
106
+ -------
107
+ dict
108
+ ``{"target_directory": str or None, "binary_name": str or None}``.
109
+ Either value is ``None`` when it cannot be resolved, in which case
110
+ callers fall back to the previous behavior.
111
+ """
112
+
113
+ if source_dir in self._workspace_layout_cache:
114
+ return self._workspace_layout_cache[source_dir]
115
+
116
+ layout = {"target_directory": None, "binary_name": None}
117
+ command = [cargo_path, "metadata", "--no-deps", "--format-version", "1"]
118
+ LOG.debug("Resolving cargo workspace layout: %s", " ".join(command))
119
+ try:
120
+ process = self._osutils.popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=source_dir)
121
+ out, err = process.communicate()
122
+ if process.returncode == 0:
123
+ metadata = json.loads(out.decode("utf-8"))
124
+ layout["target_directory"] = metadata.get("target_directory")
125
+ layout["binary_name"] = self._find_binary_name(metadata, source_dir)
126
+ self._warn_on_colliding_binaries(metadata)
127
+ else:
128
+ LOG.debug(
129
+ "Could not resolve cargo workspace layout, falling back to previous behavior: %s",
130
+ err.decode("utf-8", "replace").strip(),
131
+ )
132
+ except (OSError, ValueError, json.JSONDecodeError) as ex:
133
+ LOG.debug("Could not run cargo metadata, falling back to previous behavior: %s", ex)
134
+
135
+ self._workspace_layout_cache[source_dir] = layout
136
+ return layout
137
+
138
+ @staticmethod
139
+ def _find_binary_name(metadata, source_dir):
140
+ """
141
+ Finds the bin target name of the package whose manifest is in source_dir.
142
+ """
143
+ # cargo metadata emits absolute, symlink-resolved manifest paths, so resolve
144
+ # both operands the same way; os.path.normpath alone would never match a
145
+ # relative source_dir against cargo's absolute path.
146
+ member_manifest = os.path.realpath(os.path.join(source_dir, "Cargo.toml"))
147
+ for package in metadata.get("packages", []):
148
+ if os.path.realpath(package.get("manifest_path", "")) != member_manifest:
149
+ continue
150
+ bin_targets = [target["name"] for target in package.get("targets", []) if "bin" in target.get("kind", [])]
151
+ if len(bin_targets) == 1:
152
+ return bin_targets[0]
153
+ # A package with zero or several bins is ambiguous; let the copy step
154
+ # fall back to its directory-listing heuristic.
155
+ LOG.debug("Package %s does not have exactly one bin target: %s", package.get("name"), bin_targets)
156
+ return None
157
+ return None
158
+
159
+ @staticmethod
160
+ def _warn_on_colliding_binaries(metadata):
161
+ """
162
+ Warns when workspace members share a bin target name.
163
+
164
+ Since every member now builds into the same target/lambda directory,
165
+ two bins with the same name (e.g. several packages each defining a
166
+ `bootstrap` bin) compile to the same path and overwrite each other.
167
+ `sam build` still produces correct artifacts because it copies each
168
+ function's binary out immediately after building it, but the shared
169
+ output is fragile; unique bin names per function avoid it.
170
+ """
171
+ packages_by_bin = {}
172
+ for package in metadata.get("packages", []):
173
+ for target in package.get("targets", []):
174
+ if "bin" in target.get("kind", []):
175
+ packages_by_bin.setdefault(target["name"], []).append(package.get("name"))
176
+
177
+ for bin_name, owners in packages_by_bin.items():
178
+ if len(owners) > 1:
179
+ LOG.warning(
180
+ "Multiple workspace packages define a bin named '%s' (%s). They build to the same path in the "
181
+ "shared target directory and overwrite each other; give each function a unique bin name to "
182
+ "avoid relying on build ordering.",
183
+ bin_name,
184
+ ", ".join(sorted(owners)),
185
+ )
186
+
187
+ def run(self, command, cwd):
188
+ """
189
+ Runs the build command.
190
+
191
+ Parameters
192
+ ----------
193
+ command : str
194
+ Cargo Lambda command to run
195
+
196
+ cwd : str
197
+ Directory where to execute the command (defaults to current dir)
198
+
199
+ Returns
200
+ -------
201
+ str
202
+ Text of the standard output from the command
203
+
204
+ Raises
205
+ ------
206
+ CargoLambdaExecutionException:
207
+ Raised when the command executes with a non-zero return code. The exception will
208
+ contain the text of the standard error output from the command.
209
+ """
210
+
211
+ self.check_cargo_lambda_installation()
212
+
213
+ LOG.debug("Executing cargo-lambda: %s", " ".join(command))
214
+ if LOG.isEnabledFor(logging.DEBUG):
215
+ if "RUST_LOG" not in os.environ:
216
+ os.environ["RUST_LOG"] = "debug"
217
+ LOG.debug("RUST_LOG environment variable set to `%s`", os.environ.get("RUST_LOG"))
218
+
219
+ cargo_env = dict(os.environ)
220
+ if not cargo_env.get("CARGO_TARGET_DIR"):
221
+ # Point every build at the workspace's shared target directory so cargo
222
+ # compiles dependencies once rather than once per function. For a standalone
223
+ # project this is the project's own target directory, matching the previous
224
+ # behavior. An explicit CARGO_TARGET_DIR in the environment is left untouched.
225
+ # The first element of command is the cargo binary path.
226
+ target_directory = self.resolve_workspace_layout(command[0], cwd)["target_directory"]
227
+ # Fall back to the relative "target" the workflow used before this change when
228
+ # metadata is unavailable, so the build still lands where the copy step (which
229
+ # falls back the same way) looks for it.
230
+ cargo_env["CARGO_TARGET_DIR"] = target_directory or "target"
231
+
232
+ cargo_process = self._osutils.popen(
233
+ command,
234
+ stderr=subprocess.PIPE,
235
+ stdout=subprocess.PIPE,
236
+ cwd=cwd,
237
+ env=cargo_env,
238
+ )
239
+ stdout = ""
240
+ # Create a buffer and use a thread to gather the stderr stream into the buffer
241
+ stderr_buf = io.BytesIO()
242
+ stderr_thread = threading.Thread(
243
+ target=shutil.copyfileobj, args=(cargo_process.stderr, stderr_buf), daemon=True
244
+ )
245
+ stderr_thread.start()
246
+
247
+ # Log every stdout line by iterating
248
+ for line in cargo_process.stdout:
249
+ decoded_line = line.decode("utf-8").strip()
250
+ LOG.info(decoded_line)
251
+ # Gather total stdout
252
+ stdout += decoded_line
253
+
254
+ # Wait for the process to exit and stderr thread to end.
255
+ return_code = cargo_process.wait()
256
+ stderr_thread.join()
257
+
258
+ if return_code != 0:
259
+ # Raise an Error with the appropriate value from the stderr buffer.
260
+ raise CargoLambdaExecutionException(message=stderr_buf.getvalue().decode("utf8").strip())
261
+ return stdout
@@ -51,7 +51,7 @@ class RustCargoLambdaWorkflow(BaseWorkflow):
51
51
  handler,
52
52
  flags,
53
53
  ),
54
- RustCopyAndRenameAction(source_dir, artifacts_dir, handler),
54
+ RustCopyAndRenameAction(source_dir, artifacts_dir, handler, self.binaries, subprocess_cargo_lambda),
55
55
  ]
56
56
 
57
57
  def get_resolvers(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aws_lambda_builders
3
- Version: 1.65.0
3
+ Version: 1.66.0
4
4
  Summary: Python library to compile, build & package AWS Lambda functions for several runtimes & frameworks.
5
5
  Home-page: https://github.com/awslabs/aws-lambda-builders
6
6
  Author: Amazon Web Services
@@ -1,137 +0,0 @@
1
- """
2
- Wrapper around calling Cargo Lambda through a subprocess.
3
- """
4
-
5
- import io
6
- import logging
7
- import os
8
- import shutil
9
- import subprocess
10
- import threading
11
-
12
- from .exceptions import CargoLambdaExecutionException
13
- from .utils import OSUtils
14
-
15
- LOG = logging.getLogger(__name__)
16
-
17
-
18
- class SubprocessCargoLambda(object):
19
- """
20
- Wrapper around the Cargo Lambda command line utility, making it
21
- easy to consume execution results.
22
- """
23
-
24
- def __init__(self, which, executable_search_paths=None, osutils=OSUtils()):
25
- """
26
- Parameters
27
- ----------
28
- which : aws_lambda_builders.utils.which
29
- Function to get paths which conform to the given mode on the PATH
30
- with the prepended additional search paths
31
-
32
- executable_search_paths : list, optional
33
- List of paths to the NPM package binary utilities. This will
34
- be used to find embedded esbuild at runtime if present in the package
35
-
36
- osutils : aws_lambda_builders.workflows.rust_cargo.utils.OSUtils, optional
37
- An instance of OS Utilities for file manipulation
38
- """
39
- self._which = which
40
- self._executable_search_paths = executable_search_paths
41
- self._osutils = osutils
42
-
43
- def check_cargo_lambda_installation(self):
44
- """
45
- Checks if Cargo Lambda is in the system
46
-
47
- Returns
48
- -------
49
- str
50
- Path to the cargo-lambda binary
51
-
52
- Raises
53
- ------
54
- CargoLambdaExecutionException:
55
- Raised when Cargo Lambda is not installed in the system to run the command.
56
- """
57
-
58
- LOG.debug("checking for cargo-lambda")
59
- binaries = self._which("cargo-lambda", executable_search_paths=self._executable_search_paths)
60
- LOG.debug("potential cargo-lambda binaries: %s", binaries)
61
-
62
- if binaries:
63
- return binaries[0]
64
- else:
65
- raise CargoLambdaExecutionException(
66
- message="Cannot find Cargo Lambda. "
67
- "Cargo Lambda must be installed on the host machine to use this feature. "
68
- "Follow the gettings started guide to learn how to install it: "
69
- "https://www.cargo-lambda.info/guide/getting-started.html"
70
- )
71
-
72
- def run(self, command, cwd):
73
- """
74
- Runs the build command.
75
-
76
- Parameters
77
- ----------
78
- command : str
79
- Cargo Lambda command to run
80
-
81
- cwd : str
82
- Directory where to execute the command (defaults to current dir)
83
-
84
- Returns
85
- -------
86
- str
87
- Text of the standard output from the command
88
-
89
- Raises
90
- ------
91
- CargoLambdaExecutionException:
92
- Raised when the command executes with a non-zero return code. The exception will
93
- contain the text of the standard error output from the command.
94
- """
95
-
96
- self.check_cargo_lambda_installation()
97
-
98
- LOG.debug("Executing cargo-lambda: %s", " ".join(command))
99
- if LOG.isEnabledFor(logging.DEBUG):
100
- if "RUST_LOG" not in os.environ:
101
- os.environ["RUST_LOG"] = "debug"
102
- LOG.debug("RUST_LOG environment variable set to `%s`", os.environ.get("RUST_LOG"))
103
-
104
- if not os.getenv("CARGO_TARGET_DIR"):
105
- # This results in the "target" dir being created under the member dir of a cargo workspace
106
- # This is for supporting sam build for a Cargo Workspace project
107
- os.environ["CARGO_TARGET_DIR"] = "target"
108
-
109
- cargo_process = self._osutils.popen(
110
- command,
111
- stderr=subprocess.PIPE,
112
- stdout=subprocess.PIPE,
113
- cwd=cwd,
114
- )
115
- stdout = ""
116
- # Create a buffer and use a thread to gather the stderr stream into the buffer
117
- stderr_buf = io.BytesIO()
118
- stderr_thread = threading.Thread(
119
- target=shutil.copyfileobj, args=(cargo_process.stderr, stderr_buf), daemon=True
120
- )
121
- stderr_thread.start()
122
-
123
- # Log every stdout line by iterating
124
- for line in cargo_process.stdout:
125
- decoded_line = line.decode("utf-8").strip()
126
- LOG.info(decoded_line)
127
- # Gather total stdout
128
- stdout += decoded_line
129
-
130
- # Wait for the process to exit and stderr thread to end.
131
- return_code = cargo_process.wait()
132
- stderr_thread.join()
133
-
134
- if return_code != 0:
135
- # Raise an Error with the appropriate value from the stderr buffer.
136
- raise CargoLambdaExecutionException(message=stderr_buf.getvalue().decode("utf8").strip())
137
- return stdout