Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Go modules builder fails when using local module with provisioned.AL2 runtime

Aperta
#285 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
go
Ambito
build-system

Direzione di ricerca

Riproduci il problema con sam build utilizzando il template provided.al2 fornito, la sostituzione di go.mod della funzione e il Makefile mostrato nel report. Inizia con i passaggi CustomMakeBuilder:CopySource e CustomMakeBuilder:MakeBuild, quindi verifica che la sostituzione locale ../models rimanga disponibile durante la build. Il lavoro è completato quando la stessa applicazione Go viene compilata correttamente con provided.al2.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/workflow/go_modules maintainer/need-response

Description:
Using sam build in go projects with a dependency on a local module fails when the function runtime is Runtime: provided.al2

Steps to reproduce the issue:

  1. create a new go application sam init --name sam-app --runtime go1.x --dependency-manager mod --app-template hello-world
  2. Create a new module (here is the example I used). In a new folder called models, initialise a new module using go mod init hello-go/models

add a new go file called person.go add this code

package models

type Person struct {
	FirstName string `json:"first_name,omitempty"`
	LastName  string `json:"last_name,omitempty"`
}

func (p *Person) FullName() string {

	return p.FirstName + " " + p.LastName
}
  1. Open the main.go file for the hello0world function. Import "hello-go/models" and replace the return statement with this

	person := models.Person{FirstName: "John", LastName: "Doe"}

	return events.APIGatewayProxyResponse{
		Body:       fmt.Sprintf("Hello %s, your ip address is %v", person.FullName(), string(ip)),
		StatusCode: 200,
	}, nil

  1. Open the function go.mod file and add make sure the dependency is replaced to point to the local module
require (
	github.com/aws/aws-lambda-go v1.23.0
	hello-go/models v0.0.1
)

module hello-world

go 1.17

replace hello-go/models => ../models

  1. Build the function sam build
  2. 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"}% 
  1. Update the sam template to use Amazon Linux 2 instead of the managed runtime.

  2. 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#awsserverlessfunction
    Properties:
      CodeUri: hello-world/
      Handler: bootstrap 
      Runtime: provided.al2
      Tracing: Active # https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html
      Events:
        CatchAll:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: GET
      Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
        Variables:
          PARAM1: VALUE
    Metadata:
      BuildMethod: makefile
  1. Create a new Makefile in the hello-world function directory and add
build-HelloWorldFunction:
	GOOS=linux go build -o bootstrap
	cp ./bootstrap $(ARTIFACTS_DIR)/.
  1. 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

Lingua principale
Python
Stelle
381
Fork
162
Merge medio
1g 1h
PR unite (30g)
2

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di aws/aws-lambda-builders

Tutte le issue di aws/aws-lambda-builders

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.