Skip to content

Commit

Permalink
Move Missing BuildArchitecture warning to build_layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Bentvelsen committed Jan 3, 2024
1 parent b5503ae commit c9d5c67
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
7 changes: 7 additions & 0 deletions samcli/lib/build/app_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,13 @@ def _build_layer(
str
Path to the location where built artifacts are available
"""

if layer_metadata and "BuildArchitecture" not in layer_metadata:
LOG.warning(
"WARNING: No BuildArchitecture specifed in Layer `%s`" + " Metadata. Defaulting to x86_64.",
layer_name,
)

# Create the arguments to pass to the builder
# Code is always relative to the given base directory.
code_dir = str(pathlib.Path(self._base_dir, codeuri).resolve())
Expand Down
6 changes: 0 additions & 6 deletions samcli/lib/providers/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,6 @@ def __init__(
self._compatible_runtimes = compatible_runtimes
self._custom_layer_id = metadata.get(SAM_RESOURCE_ID_KEY)

if "BuildArchitecture" not in metadata:
LOG.warning(
"WARNING: No BuildArchitecture specifed in Layer `%s`" + " Metadata. Defaulting to x86_64.",
self._custom_layer_id,
)

self._build_architecture = cast(str, metadata.get("BuildArchitecture", X86_64))
self._compatible_architectures = compatible_architectures

Expand Down
10 changes: 10 additions & 0 deletions tests/integration/buildcmd/test_build_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,16 @@ def test_build_fails_with_missing_metadata(self, runtime, use_container, layer_i
self.assertEqual(command_result.process.returncode, 1)
self.assertFalse(self.default_build_dir.joinpath(layer_identifier).exists())

def test_function_build_succeeds_with_referenced_layer(self):
overrides = {"Runtime": "python3.8"}
cmdlist = self.get_command_list(
use_container=False, parameter_overrides=overrides, function_identifier="FunctionTwo"
)

command_result = run_command(cmdlist, cwd=self.working_dir)
self.assertEqual(command_result.process.returncode, 0)
self.assertNotIn("No BuildArchitecture specifed", str(command_result.stderr))

@parameterized.expand([("python3.7", False, "LayerOne"), ("python3.7", "use_container", "LayerOne")])
def test_build_with_missing_buildarchitecture(self, runtime, use_container, layer_identifier):
if use_container and (SKIP_DOCKER_TESTS or SKIP_DOCKER_BUILD):
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/testdata/buildcmd/layers-functions-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ Resources:
Layers:
- !Ref LayerOne

FunctionTwo:
Type: AWS::Serverless::Function
Properties:
Handler: !Ref Handler
Runtime: !Ref Runtime
CodeUri: !Ref CodeUri
Timeout: 600
Layers:
- !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:012345678912:layer:layerName:1

LayerOne:
Type: AWS::Serverless::LayerVersion
Properties:
Expand Down

0 comments on commit c9d5c67

Please sign in to comment.