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

Mounting handler functions in v0.2.2 #170

Closed
sjukkola opened this issue Oct 16, 2017 · 3 comments
Closed

Mounting handler functions in v0.2.2 #170

sjukkola opened this issue Oct 16, 2017 · 3 comments

Comments

@sjukkola
Copy link

Mounting handler functions shows inconsistent behaviour when upgrading version from 0.2.0 to 0.2.2. Has this something to do with http router rewrite?

I have a project structure like following

├── src
│   ├── product.js
│   └── images.js
├── templates
│   ├── template.yaml  

Problem 1

CodeUri: ../src is not working anymore. Resolving module will fail. Only workaround I have found is to move template.yaml to project root and use CodeUri: src/.

Problem 2

Invalid logs at startup

Runningsam local start-api --template template/template.yaml gets me following:

v0.2.0

Mounting images.handler (nodejs6.10) at http://127.0.0.1:3000/images [GET]
Mounting products.handler (nodejs6.10) at http://127.0.0.1:3000/products [GET]

v0.2.2

Mounting products.handler (nodejs6.10) at http://127.0.0.1:3000/images [GET]
Mounting products.handler (nodejs6.10) at http://127.0.0.1:3000/products [GET]
@joshuahiggins
Copy link

joshuahiggins commented Jan 10, 2018

I was just about to open a new issue regarding the logs when I found this, which happens to also cover the relative pathing issue I opened earlier today. Closing #258 now and adding what I found regarding relative paths below:


As far as I can tell from reading over the source (forgive me, I've never worked in Go), the issue resides here: https://github.com/awslabs/aws-sam-local/blob/bd1672469e85bf533ee10849773ee7c92a854411/runtime.go#L262-L290

When the API runtime is instantiated, the Cwd is set to the template directory. However, if the CodeUri is a directory path than the Cwd will be overwritten on every invocation of an endpoint, by appending the CodeUri to the end of it. As such, if you have .. (or anything starting with ../) in your CodeUri, your working directory will move up one directory level for each invocation.

As an example, let's assume a project serverless-app has a templates folder for CFN templates and a src folder for handlers. Our API endpoint is set to CodeUri: .. and Handler: src/example.handler.

  • When local SAM starts, Cwd is set on the runtime as: /Users/user/serverless-app/templates/
  • On first invoking, Cwd has CodeUri appended to it, resulting in a new path of /Users/user/serverless-app/templates/... The handler works correctly.
  • On second invoking, Cwd has CodeUri appended to it again, and now the path is /Users/user/serverless-app/... Not the handlers are wrong.
  • Each invoking to follow does the same.

This can be countered by setting --docker-volume-basedir $(pwd) at start. However I felt it was worth bringing up still, as it's my personal feeling that the Cwd of the runtime should not be rewritten on every invocation. The working directory should remain static.

@include
Copy link

include commented May 8, 2018

I'm having the same problem.

Mounting lf_listjobs.lambda_handler (python3.6) at http://127.0.0.1:3000/addjob [PUT]
Mounting lf_listjobs.lambda_handler (python3.6) at http://127.0.0.1:3000/ [GET]

sam version 0.2.11

@sanathkr
Copy link
Contributor

sanathkr commented May 8, 2018

Can you try the latest release - https://github.com/awslabs/aws-sam-cli/releases/tag/v0.3.0? I believe this is fixed. Feel free to re-open Issue if not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants