Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: golang sam local start-api doesn't work without a .aws-sam from sam build #4784

Closed
danludwig opened this issue Feb 28, 2023 · 4 comments
Labels
area/local/invoke sam local invoke command area/local/start-api sam local start-api command type/question

Comments

@danludwig
Copy link

Description:

Running sam local start-api without a .aws-sam build output in a default go1.x runtime results in an error when the api is invoked. The error does not occur when running make build or sam build, but does recur when the .aws-sam output is removed.

Steps to reproduce:

The following steps were executed and pushed here for a reference reproduction.

sam init --name sam-app0 --runtime go1.x
  • Select (1) AWS Quick Start Templates
  • Select (1) Hello World Example
  • Select remaining (N) defaults
cd sam-app0
  • Do not run sam build or make build, if there is a .aws-sam folder, delete it
sam local start-api --debug
curl http://localhost:3000/hello

Observed result:

From curl:

{"message":"Internal server error"}

The CLI output is:

You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. If you used sam build before running local commands, you will need to re-run sam build for the changes to be picked up.

2023-02-28 16:57:04,757 | Found one Lambda function with name 'HelloWorldFunction'
2023-02-28 16:57:04,757 | Invoking hello-world (go1.x)
2023-02-28 16:57:04,757 | Resolving code path. Cwd=/Users/dan/code/github/danludwig/aws-sam-cli-bug-reports/v1.75.0/golang-sam-local-start-api, CodeUri=/Users/dan/code/github/danludwig/aws-sam-cli-bug-reports/v1.75.0/golang-sam-local-start-api/hello-world
2023-02-28 16:57:04,757 | Resolved absolute path to code is /Users/dan/code/github/danludwig/aws-sam-cli-bug-reports/v1.75.0/golang-sam-local-start-api/hello-world
2023-02-28 16:57:04,764 | Reuse the created warm container for Lambda function 'HelloWorldFunction'
2023-02-28 16:57:04,769 | Lambda function 'HelloWorldFunction' is already running
2023-02-28 16:57:04,771 | Starting a timer for 5 seconds for function 'HelloWorldFunction'
START RequestId: 1fb75e5a-dc58-4676-80bf-164ea836860e Version: $LATEST
fork/exec /var/task/hello-world: no such file or directory: PathError
null
2023-02-28 16:57:04,805 | Unable to find Click Context for getting session_id.
2023-02-28 16:57:04,806 | Lambda returned empty body!
2023-02-28 16:57:04,806 | Invalid lambda response received: Invalid API Gateway Response Keys: {'errorMessage', 'errorType'} in {'errorMessage': 'fork/exec /var/task/hello-world: no such file or directory', 'errorType': 'PathError'}
2023-02-28 16:57:04 127.0.0.1 - - [28/Feb/2023 16:57:04] "GET /hello HTTP/1.1" 502 -
END RequestId: 1fb75e5a-dc58-4676-80bf-164ea836860e
REPORT RequestId: 1fb75e5a-dc58-4676-80bf-164ea836860e Init Duration: 0.19 ms Duration: 16.96 ms Billed Duration: 17 ms Memory Size: 128 MB Max Memory Used: 128 MB

Expected result:

From curl:

Hello, ${IP_ADDRESS}

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

  1. OS: Mac Intel 2019
  2. sam --version: 1.75.0
  3. AWS region: localhost
{
  "version": "1.75.0",
  "system": {
    "python": "3.11.2",
    "os": "macOS-13.2.1-x86_64-i386-64bit"
  },
  "additional_dependencies": {
    "docker_engine": "20.10.21",
    "aws_cdk": "Not available",
    "terraform": "1.3.7"
  }
}
@danludwig danludwig added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Feb 28, 2023
@sriram-mv
Copy link
Contributor

sriram-mv commented Feb 28, 2023

for compiled languages specifically, one would need to build before trying to local invoke (its the same with interpreted languages with dependencies outside of the standard library). This is not a bug per se, but how we envision users using the tool as workflow i.e building before local invoking. Would something like auto-build before invoke be what you are referring to?

@sriram-mv sriram-mv added type/question area/local/start-api sam local start-api command area/local/invoke sam local invoke command and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Feb 28, 2023
@mndeveci
Copy link
Contributor

mndeveci commented Sep 6, 2023

As @sriram-mv mentioned, sam build should be run first for compiled languages. Even for interpreted ones, if function has external dependencies, sam build should run first in order sam local to succeed.

Resolving this issue due to inactivity.

@mndeveci mndeveci closed this as not planned Won't fix, can't repro, duplicate, stale Sep 6, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 6, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@bujosa
Copy link

bujosa commented Oct 31, 2023

@mndeveci @sriram-mv Thank u so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local/invoke sam local invoke command area/local/start-api sam local start-api command type/question
Projects
None yet
Development

No branches or pull requests

4 participants