aws / aws-lambda-builders

Python library to compile, build & package AWS Lambda functions for several runtimes & framework
Apache License 2.0
334 stars 139 forks source link

Bug: sam build GoModulesBuilder fails to output the relevant error message, outputs "directory not found" instead #676

Open distinctdan opened 1 month ago

distinctdan commented 1 month ago

Description:

When my Go code has a syntax error, I expect sam build to display the error. Instead, it's showing a generic error:

Error: GoModulesBuilder:Build - Builder Failed: stat /Users/my.user/my-project/myproject/bootstrap: directory not found

In my template.yaml, here's the relevant block for my Go lambda:

Resources:
  MyFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Metadata:
      BuildMethod: go1.x
    Properties:
      CodeUri: myproject/
      Handler: bootstrap
      Runtime: provided.al2023
      Architectures:
        - x86_64

I have a file myproject/bootstrap.go that contains func main() { lambda.Start(handler) }.

Steps to reproduce:

Create any syntax error, like renaming a function from MyFunc to MyFunc2

Observed result:

A "directory not found" error.

Expected result:

The output from go build which shows the actual error.

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

  1. OS: OSX Sonoma 14.6.1
  2. sam --version: SAM CLI, version 1.121.0
  3. AWS region: N/a
{
  "version": "1.121.0",
  "system": {
    "python": "3.8.13",
    "os": "macOS-14.6.1-x86_64-i386-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "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"
  ]
}
hawflau commented 1 month ago

@distinctdan thanks for raising the issue. I could re-produce your issue. It seems to me that Lambda Builders does not check the status code when building the go package but instead just checks for the existence of the output binary. This is a bug we should fix.