Skip to content

Bug: sam build --use-container fails for go1.x on provided.al2/al2023 runtimes #5280

@davidjb

Description

@davidjb

Description:

The standard go1.x runtime is based on AL1, which is both EOL and doesn't support ARM-based CPUs. The suggested replacement is to use the provided.al2 or provided.al20223 runtimes with BuildMethod: go1.x. This works sam build is run locally but only on hosts where issues like aws/aws-lambda-go#340 don't occur. In order to create a normalised build environment, I attempted to build with sam build --use-container instead, which errors with:

aws_lambda_builders.exceptions.WorkflowFailedError: GoModulesBuilder:Resolver - Path resolution for runtime: provided of binary: go was not successful

The reason for this is that the go binary is not present within the sam/build-provided.al2 image and thus preventing builds. A PR had been created at aws/aws-sam-build-images#71 to add Go into the provided and provided.al2 runtimes but is under discussion as of the end of 2022.

Steps to reproduce:

  1. Specify a lambda function in template.yml:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Metadata:
      BuildMethod: go1.x
    Properties:
      CodeUri: functions/myfunction/
      Handler: bootstrap
      Runtime: provided.[al2|al2023]
      Architectures: [arm64]
  1. Run sam build --use-container.

Observed result:

$ sam build --use-container --debug
2023-06-07 12:39:32,226 | Config file location: /Users/me/project/samconfig.toml
2023-06-07 12:39:32,226 | Config file '/Users/me/project/samconfig.toml' does not exist
2023-06-07 12:39:32,227 | Using SAM Template at /Users/me/project/template.yml
2023-06-07 12:39:32,242 | Using config file: samconfig.toml, config environment: default
2023-06-07 12:39:32,242 | Expand command line arguments to:
2023-06-07 12:39:32,242 | --template_file=/Users/me/project/template.yml --use_container --mount_with=READ --build_dir=.aws-sam/build --cache_dir=.aws-sam/cache
2023-06-07 12:39:32,302 | 'build' command is called
2023-06-07 12:39:32,302 | Starting Build inside a container
2023-06-07 12:39:32,303 | No Parameters detected in the template
2023-06-07 12:39:32,313 | There is no customer defined id or cdk path defined for resource MyFunction, so we will use the resource logical id as the resource id
2023-06-07 12:39:32,313 | 0 stacks found in the template
2023-06-07 12:39:32,314 | No Parameters detected in the template
2023-06-07 12:39:32,321 | There is no customer defined id or cdk path defined for resource MyFunction, so we will use the resource logical id as the resource id
2023-06-07 12:39:32,321 | 1 resources found in the stack
2023-06-07 12:39:32,321 | Found Serverless function with name='MyFunction' and CodeUri='functions/myfunction/'
2023-06-07 12:39:32,321 | --base-dir is not presented, adjusting uri functions/myfunction/ relative to /Users/me/project/template.yml
2023-06-07 12:39:32,322 | 1 resources found in the stack
2023-06-07 12:39:32,322 | Found Serverless function with name='MyFunction' and CodeUri='functions/myfunction/'
2023-06-07 12:39:32,323 | Instantiating build definitions
2023-06-07 12:39:32,324 | Same function build definition found, adding function (Previous: BuildDefinition(provided.al2, /Users/me/project/functions/myfunction, Zip, , 1e222f6c-cb64-4fce-8a77-41ed2bea56bb, {'BuildMethod': 'go1.x'}, {}, arm64, []), Current: BuildDefinition(provided.al2, /Users/me/project/functions/myfunction, Zip, , 634c58e1-f958-46a9-800e-69617725ab30, {'BuildMethod': 'go1.x'}, {}, arm64, []), Function: Function(function_id='MyFunction', name='MyFunction', functionname='MyFunction', runtime='provided.al2', memory=None, timeout=None, handler='bootstrap', imageuri=None, packagetype='Zip', imageconfig=None, codeuri='/Users/me/project/functions/myfunction', environment=None, rolearn=None, layers=[], events=None, metadata={'BuildMethod': 'go1.x', 'SamResourceId': 'MyFunction'}, inlinecode=None, codesign_config_arn=None, architectures=['arm64'], function_url_config=None, stack_path='', runtime_management_config=None))
2023-06-07 12:39:32,325 | Building codeuri: /Users/me/project/functions/myfunction runtime: provided.al2 metadata: {'BuildMethod': 'go1.x'} architecture: arm64 functions: MyFunction
2023-06-07 12:39:32,325 | Building to following folder /Users/me/project/.aws-sam/build/MyFunction

Fetching public.ecr.aws/sam/build-provided.al2:latest-arm64 Docker container image......
2023-06-07 12:39:35,721 | Mounting /Users/me/project/functions/myfunction as /tmp/samcli/source:ro,delegated, inside runtime container
Using the request object from command line argument
Loading workflow module 'aws_lambda_builders.workflows'
Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None, application_framework=None)'
Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules', application_framework=None)'
Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle', application_framework=None)'
Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven', application_framework=None)'
Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm', application_framework=None)'
Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm-esbuild', application_framework=None)'
Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip', application_framework=None)'
Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler', application_framework=None)'
Registering workflow 'RustCargoLambdaBuilder' with capability 'Capability(language='rust', dependency_manager='cargo', application_framework=None)'
Found workflow 'GoModulesBuilder' to support capabilities 'Capability(language='go', dependency_manager='modules', application_framework=None)'
Builder workflow failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 78, in wrapper
    if not binary_checker.path_provided
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/path_resolver.py", line 33, in exec_paths
    return self._which()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/path_resolver.py", line 27, in _which
    "Path resolution for runtime: {} of binary: " "{} was not successful".format(self.runtime, self.binary)
ValueError: Path resolution for runtime: provided of binary: go was not successful

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/__main__.py", line 133, in main
    build_in_source=params.get("build_in_source", None),
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/builder.py", line 170, in build
    return workflow.run()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 82, in wrapper
    raise WorkflowFailedError(workflow_name=self.NAME, action_name="Resolver", reason=str(ex))
aws_lambda_builders.exceptions.WorkflowFailedError: GoModulesBuilder:Resolver - Path resolution for runtime: provided of binary: go was not successful
2023-06-07 12:39:36,080 | Build inside container returned response {"jsonrpc": "2.0", "id": 1, "error": {"code": 400, "message": "GoModulesBuilder:Resolver - Path resolution for runtime: provided of binary: go was not successful"}}

Build Failed
2023-06-07 12:39:36,158 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-06-07 12:39:36,159 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-06-07 12:39:36,160 | Unable to find Click Context for getting session_id.
Error: GoModulesBuilder:Resolver - Path resolution for runtime: provided of binary: go was not successful

Expected result:

Build to succeed and not error with --use-container.

Alternatively, if there was a way to set local environment variables such they're passed to go build locally (e.g. when containers aren't used), that would be a workaround to the initial problem.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

{
  "version": "1.85.0",
  "system": {
    "python": "3.8.16",
    "os": "macOS-13.4-arm64-arm-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "23.0.5",
    "aws_cdk": "Not available",
    "terraform": "1.1.0"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions