You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you run sam local invoke "HelloWorldFunction" you should see the output (with your IP address)
{"statusCode":200,"headers":null,"multiValueHeaders":null,"body":"Hello John Doe, your ip address is 127.0.0.1\n"}%
Update the sam template to use Amazon Linux 2 instead of the managed runtime.
In the function definition replace handler and runtime properties, and the Metadata resource attribute
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunctionProperties:
CodeUri: hello-world/Handler: bootstrap Runtime: provided.al2Tracing: Active # https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.htmlEvents:
CatchAll:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#apiProperties:
Path: /helloMethod: GETEnvironment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-objectVariables:
PARAM1: VALUEMetadata:
BuildMethod: makefile
Create a new Makefile in the hello-world function directory and add
build-HelloWorldFunction:
GOOS=linux go build -o bootstrap
cp ./bootstrap $(ARTIFACTS_DIR)/.
Run sam build. The build now fails.
Observed result:
sam build
Building codeuri: /Users/sliedig/go/src/hello-go-al2/hello-world runtime: provided.al2 metadata: {'BuildMethod': 'makefile'} functions: ['HelloWorldFunction']
Running CustomMakeBuilder:CopySource
Running CustomMakeBuilder:MakeBuild
Current Artifacts Directory : /Users/sliedig/go/src/hello-go-al2/.aws-sam/build/HelloWorldFunction
Build Failed
Error: CustomMakeBuilder:MakeBuild - Make Failed: main.go:9:2: hello-go-al2/[email protected]: replacement directory ../models does not exist
make[1]: *** [build-HelloWorldFunction] Error 1
make: *** [build] Error 1
Expected result:
I would expect the sam build system to correctly build my application irrespective of whether I am using go as a managed runtime or on AL2.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
OS: Darwin x64 20.6.0
go version go1.17.1 darwin/amd64
SAM CLI, version 1.32.0
The text was updated successfully, but these errors were encountered:
I have also noticed in Python projects, if you have local modules you want to share across functions that SAM build does not include those either. Seems the way to get around it is to do some layers voodoo but that seems like complete overkill for something that works natively.
@sliedig, the problem is with Running CustomMakeBuilder:CopySource which copies hello-world/ (your CodeUri) into a scratch directory (think a random directory under your OS temp folder) and then runs the go build commands. This means in that new scratch directory ../models does not make sense anymore as you are in a completely different directory.
I am about to open an issue myself asking why we even have the scratch path for the custom makefile builder and all the issues I see with it.
Description:
Using
sam build
in go projects with a dependency on a local module fails when the function runtime isRuntime: provided.al2
Steps to reproduce the issue:
sam init --name sam-app --runtime go1.x --dependency-manager mod --app-template hello-world
go mod init hello-go/models
add a new go file called person.go add this code
sam build
sam local invoke "HelloWorldFunction"
you should see the output (with your IP address)Update the sam template to use Amazon Linux 2 instead of the managed runtime.
In the function definition replace handler and runtime properties, and the Metadata resource attribute
sam build
. The build now fails.Observed result:
Expected result:
I would expect the sam build system to correctly build my application irrespective of whether I am using go as a managed runtime or on AL2.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
OS: Darwin x64 20.6.0
go version go1.17.1 darwin/amd64
SAM CLI, version 1.32.0
The text was updated successfully, but these errors were encountered: