Sam Build fails to build a go lambda functions when usin --use-container
flag
#6460
Labels
stage/needs-triage
Automatically applied to new issues and PRs, indicating they haven't been looked at.
Description:
I am trying to build and run a lambda locally using the sam cli but the build keeps failing with below error message
Error: GoModulesBuilder:Build - Builder Failed: go: go.mod file not found in current directory or any parent directory; see 'go help modules'
Steps to reproduce:
Here is my stack and command that I am running
Build Template:
AWSTemplateFormatVersion: "2010-09-09" Transform: AWS::Serverless-2016-10-31 Resources: Function: Type: AWS::Serverless::Function Metadata: BuildMethod: go1.x Properties: Timeout: 300 MemorySize: 128 Handler: main CodeUri: /Users/zahaf002/go/src/app/liveactivity/ Runtime: go1.x
Build Command:
% /usr/local/bin/sam build Function --template template.yaml --build-dir .aws-sam/.aws-sam/build --use-container --debug
Observed result:
I am getting below error:
Error: GoModulesBuilder:Build - Builder Failed: go: go.mod file not found in current directory or any parent directory; see 'go help modules'
Debug outpout:
`
2023-12-15 11:54:30,586 | No config file found in this directory.
2023-12-15 11:54:30,590 | OSError occurred while reading TOML file: [Errno 2] No such file or directory:
'/Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/.aws-sam/samconfig.toml'
2023-12-15 11:54:30,592 | Config file location: /Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/.aws-sam/samconfig.toml
2023-12-15 11:54:30,593 | Config file '/Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/.aws-sam/samconfig.toml' does not exist
2023-12-15 11:54:30,632 | OSError occurred while reading TOML file: [Errno 2] No such file or directory:
'/Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/.aws-sam/samconfig.toml'
2023-12-15 11:54:30,633 | Using config file: samconfig.toml, config environment: default
2023-12-15 11:54:30,634 | Expand command line arguments to:
2023-12-15 11:54:30,635 | --template_file=/Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/.aws-sam/liveactivity-processing-template.yaml
--build_dir=/Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/.aws-sam/.aws-sam/build --use_container --resource_logical_id=Function --mount_with=READ --cache_dir=.aws-sam/cache
2023-12-15 11:54:30,687 | 'build' command is called
2023-12-15 11:54:30,689 | Starting Build inside a container
2023-12-15 11:54:30,692 | No Parameters detected in the template
2023-12-15 11:54:30,746 | There is no customer defined id or cdk path defined for resource Function, so we will use the resource logical id as the resource id
2023-12-15 11:54:30,748 | 0 stacks found in the template
2023-12-15 11:54:30,749 | No Parameters detected in the template
2023-12-15 11:54:30,781 | There is no customer defined id or cdk path defined for resource Function, so we will use the resource logical id as the resource id
2023-12-15 11:54:30,782 | 1 resources found in the stack
2023-12-15 11:54:30,783 | Found Serverless function with name='Function' and CodeUri='/Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/app/liveactivity/'
2023-12-15 11:54:30,784 | --base-dir is not presented, adjusting uri /Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/app/liveactivity/ relative to
/Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/.aws-sam/liveactivity-processing-template.yaml
2023-12-15 11:54:30,790 | 1 resources found in the stack
2023-12-15 11:54:30,791 | Found Serverless function with name='Function' and CodeUri='/Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/app/liveactivity/'
2023-12-15 11:54:30,793 | Instantiating build definitions
2023-12-15 11:54:30,794 | No previous build graph found, generating new one
2023-12-15 11:54:30,795 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(go1.x,
/Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/app/liveactivity/, Zip, , 1e3fe872-1511-46d0-a1b0-31d449007642, {'BuildMethod': 'go1.x'}, {}, x86_64, []), Function:
Function(function_id='Function', name='Function', functionname='Function', runtime='go1.x', memory=128, timeout=300, handler='main', imageuri=None, packagetype='Zip', imageconfig=None,
codeuri='/Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/app/liveactivity/', environment=None, rolearn=None, layers=[], events=None, metadata={'BuildMethod': 'go1.x',
'SamResourceId': 'Function'}, inlinecode=None, codesign_config_arn=None, architectures=None, function_url_config=None, function_build_info=<FunctionBuildInfo.BuildableZip: ('BuildableZip', 'Regular ZIP function which
can be build with SAM CLI')>, stack_path='', runtime_management_config=None, logging_config=None))
2023-12-15 11:54:30,800 | Building codeuri: /Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/app/liveactivity/ runtime: go1.x metadata: {'BuildMethod': 'go1.x'} architecture:
x86_64 functions: Function
2023-12-15 11:54:30,802 | Building to following folder /Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/.aws-sam/.aws-sam/build/Function
2023-12-15 11:54:36,422 | Checking free port on 127.0.0.1:8521
Fetching public.ecr.aws/sam/build-go1.x:latest-x86_64 Docker container image......
2023-12-15 11:54:38,010 | Mounting /Users/zahaf002/go/src/gitlab.disney.com/dtci-native-app/services/distribution/distroapi/app/liveactivity 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)'
Workflow GoModulesBuilder does not support value "False" for building in source. Using default value "True".
Running workflow 'GoModulesBuilder'
Running GoModulesBuilder:Build
go: go.mod file not found in current directory or any parent directory; see 'go help modules'
Go files not found. Attempting to build for Go files in a different directory
Go files not found at CodeUri /tmp/samcli/source . Descending into sub-directories to find the handler: /tmp/samcli/source/main
GoModulesBuilder:Build failed
Traceback (most recent call last):
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/workflows/go_modules/actions.py", line 22, in execute
self.builder.build(self.source_dir, self.output_path)
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/workflows/go_modules/builder.py", line 77, in build
raise BuilderError(message=p_err.decode("utf8").strip())
aws_lambda_builders.workflows.go_modules.builder.BuilderError: Builder Failed: go: go.mod file not found in current directory or any parent directory; see 'go help modules'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/workflow.py", line 371, in run
action.execute()
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/workflows/go_modules/actions.py", line 24, in execute
raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Builder Failed: go: go.mod file not found in current directory or any parent directory; see 'go help modules'
Builder workflow failed
Traceback (most recent call last):
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/workflows/go_modules/actions.py", line 22, in execute
self.builder.build(self.source_dir, self.output_path)
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/workflows/go_modules/builder.py", line 77, in build
raise BuilderError(message=p_err.decode("utf8").strip())
aws_lambda_builders.workflows.go_modules.builder.BuilderError: Builder Failed: go: go.mod file not found in current directory or any parent directory; see 'go help modules'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/workflow.py", line 371, in run
action.execute()
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/workflows/go_modules/actions.py", line 24, in execute
raise ActionFailedError(str(ex))
aws_lambda_builders.actions.ActionFailedError: Builder Failed: go: go.mod file not found in current directory or any parent directory; see 'go help modules'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/main.py", line 117, in main
builder.build(
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/builder.py", line 170, in build
return workflow.run()
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/workflow.py", line 115, in wrapper
func(self, *args, **kwargs)
File "/usr/local/opt/lambda-builders/lib64/python3.8/site-packages/aws_lambda_builders/workflow.py", line 378, in run
raise WorkflowFailedError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex))
aws_lambda_builders.exceptions.WorkflowFailedError: GoModulesBuilder:Build - Builder Failed: go: go.mod file not found in current directory or any parent directory; see 'go help modules'
2023-12-15 11:54:38,689 | Build inside container returned response {"jsonrpc": "2.0", "id": 1, "error": {"code": 400, "message": "GoModulesBuilder:Build - Builder Failed: go: go.mod file not found in current directory
or any parent directory; see 'go help modules'"}}
Build Failed
2023-12-15 11:54:38,810 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-12-15 11:54:38,904 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2023-12-15 11:54:38,906 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': '91685a65-1c90-4410-beb3-5d4fadee8c8b', 'installationId': 'b8e30215-3b0c-4a53-b7e0-4b9ccad4c858', 'sessionId':
'f70b3040-3786-465f-9ade-15fbd9e314f9', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.13', 'samcliVersion': '1.105.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '',
'commandName': 'sam build', 'metricSpecificAttributes': {'projectType': 'CFN', 'gitOrigin': None, 'projectName': '2d0acff394264269b272dd8200322eb0b9b9372e3be7240380226263de49f51e', 'initialCommit': None}, 'duration':
8176, 'exitReason': 'BuildInsideContainerError', 'exitCode': 1}}]}
2023-12-15 11:54:38,907 | Unable to find Click Context for getting session_id.
2023-12-15 11:54:38,913 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'fa191760-4b1b-4b77-b1e2-302343e2fd33', 'installationId': 'b8e30215-3b0c-4a53-b7e0-4b9ccad4c858', 'sessionId':
'f70b3040-3786-465f-9ade-15fbd9e314f9', 'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.8.13', 'samcliVersion': '1.105.0', 'commandName': 'sam build', 'metricSpecificAttributes': {'events': [{'event_name':
'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '9d72c83ee05a40f0a657b02c6cb25ff2', 'time_stamp': '2023-12-15 19:54:30.592', 'exception_name': None}, {'event_name': 'SamConfigFileExtension',
'event_value': '.toml', 'thread_id': '65882cf7c7fc446b996aaa5701f9725c', 'time_stamp': '2023-12-15 19:54:30.633', 'exception_name': None}, {'event_name': 'BuildWorkflowUsed', 'event_value': 'go-modules', 'thread_id':
'b37ef74621494bc0ae3a1f05d260e45e', 'time_stamp': '2023-12-15 19:54:30.793', 'exception_name': None}, {'event_name': 'BuildFunctionRuntime', 'event_value': 'go1.x', 'thread_id': '34a1a629950a43b9a98d56a42a609d91',
'time_stamp': '2023-12-15 19:54:30.793', 'exception_name': None}, {'event_name': 'BuildWorkflowUsed', 'event_value': 'go-modules', 'thread_id': 'a3d591aa8d7e4b1498a89b41cba5c724', 'time_stamp': '2023-12-15
19:54:30.803', 'exception_name': None}]}}}]}
2023-12-15 11:54:39,127 | Telemetry response: 200
Error: GoModulesBuilder:Build - Builder Failed: go: go.mod file not found in current directory or any parent directory; see 'go help modules'
`
The text was updated successfully, but these errors were encountered: