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

Use with docker-compose? #1

Open
GeoffreyBooth opened this issue Nov 1, 2017 · 1 comment · May be fixed by #2
Open

Use with docker-compose? #1

GeoffreyBooth opened this issue Nov 1, 2017 · 1 comment · May be fixed by #2

Comments

@GeoffreyBooth
Copy link

GeoffreyBooth commented Nov 1, 2017

I’m trying to use this in start-api mode with docker-compose. I have this in my docker-compose.yml file:

version: '3'

services:
  amazon:
    image: cnadiminti/aws-sam-local
    command: local start-api --host 0.0.0.0 --docker-volume-basedir /var/opt
    ports:
      - '3000:3000'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./amazon:/var/opt

With the code from https://github.com/awslabs/aws-sam-local/tree/develop/samples/api-event-source in ./amazon. The container starts up, and seems to load template.yml just fine:

amazon_1   | nodejs6.10: Pulling from lambci/lambda
amazon_1   | Digest: sha256:7eb4ced6a15ae3c30effc4ec0cd3aabb2bd57c9a8330b37920c3d5d722d81083
amazon_1   | Status: Image is up to date for lambci/lambda:nodejs6.10
amazon_1   |
amazon_1   | Mounting index.handler (nodejs6.10) at http://0.0.0.0:3000/ [OPTIONS GET HEAD POST PUT DELETE TRACE CONNECT]
amazon_1   | Mounting static files from /var/opt/public at /
amazon_1   |
amazon_1   | You can now browse to the above endpoints to invoke your functions.
amazon_1   | You do not need to restart/reload SAM CLI while working on your functions,
amazon_1   | changes will be reflected instantly/automatically. You only need to restart
amazon_1   | SAM CLI if you update your AWS SAM template.
amazon_1   |

But hitting http://localhost:3000/ throws an error:

amazon_1   | 2017/11/01 06:48:24 Invoking index.handler (nodejs6.10)
amazon_1   | START RequestId: a0b9d93e-517e-1bbe-6ffb-d8ad37e1d5db Version: $LATEST
amazon_1   | Unable to import module 'index': Error
amazon_1   |     at Function.Module._resolveFilename (module.js:469:15)
amazon_1   |     at Function.Module._load (module.js:417:25)
amazon_1   |     at Module.require (module.js:497:17)
amazon_1   |     at require (internal/module.js:20:19)
amazon_1   | END RequestId: a0b9d93e-517e-1bbe-6ffb-d8ad37e1d5db
amazon_1   | REPORT RequestId: a0b9d93e-517e-1bbe-6ffb-d8ad37e1d5db	Duration: 12.61 ms	Billed Duration: 0 ms	Memory Size: 0 MB	Max Memory Used: 28 MB
amazon_1   | 2017/11/01 06:48:45 Function returned an invalid response (must include one of: body, headers or statusCode in the response object): %!s(<nil>)

The files in that folder work fine via sam local start-api, so it’s not a file path issue.

@GeoffreyBooth
Copy link
Author

GeoffreyBooth commented Nov 1, 2017

I got this to work. --docker-volume-basedir needs to reference a path on the host, e.g. /Users/Geoffrey/Sites/project/amazon on my Mac, not /var/opt inside the container as I expected it to be. Submitted #2 to document this as an example for others.

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

Successfully merging a pull request may close this issue.

1 participant