question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sam-local inside CodeBuild Docker container

See original GitHub issue

I have a fairly simple use-case. I want to run aws-sam-local as part of ci/cd. I use aws codebuild for building my backend. I would like run sam-local in the background as part of a post build process. Therefore, I can run integration tests against the local server and possibly fail the build before deploying.

I don’t have any issue running the NPM installed sam-local CLI in the foreground simply with: sam local start-api --env-vars ./src/config/env/test.json

But when I try to use something like nohup per https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-background-tasks.html with the CLI, I get Connection refused

I also don’t have any issues running the https://github.com/cnadiminti/docker-aws-sam-local container in the foreground with the privileged flag set in my CodeBuild container. However, if I use the -d parameter of Docker I get Connection reset by peer Buildspec.yaml example:

 - docker run -d -t
    -v /var/run/docker.sock:/var/run/docker.sock
    -v $(pwd):/var/opt
    -p 3000:3000
    cnadiminti/aws-sam-local
    local start-api --env-vars ./config/env/local.json --docker-volume-basedir $(pwd) --host 0.0.0.0

Maybe I’m thinking about this the wrong way but it seems like running aws-sam-local in a container within my CodeBuild process and hitting the local server with my integration test suite would be suitable. I’m aware of the drawbacks of using Docker in Docker.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
piotrkubisacommented, Apr 25, 2018

Not so long ago I created localci to run CodeBuild locally using official AWS Docker images to help me inspect some problems during AWS CodeBuild runtime. You may try it or just run CodeBuild’s Docker images locally and try out to resolve your issue - they are well-documented and easy to play with.

Personally, after 4 months of using sam-local I cannot recommend it to rely on it during some functional/postman tests in start-api mode. I’d rather go with mocking event payload (from API Gateway) and invidually call all methods which requires such functional testing. In my humble opinnion, there is still a lot of differences if you do a curl request to real deployment on API Gateway with AWS Lambda and to aws-sam-local which mimics them (i.e. retrieving resources after gzip/deflate compression). During functional tests aws-sam-local might be an extra PoF which may cause false-positive/negative test results.

0reactions
jfusscommented, Oct 13, 2020

Closing. Docker in Docker is not something we currently support. Please run same outside of docker to use sam local or sam build --use-container.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sam-local inside CodeBuild Docker container #334 - GitHub
I have a fairly simple use-case. I want to run aws-sam-local as part of ci/cd. I use aws codebuild for building my backend....
Read more >
Using container image support for AWS Lambda with AWS SAM
When using container-based images, as you modify your code, update the local container image using sam build . AWS SAM then calls docker...
Read more >
Integrating AWS CDK Pipelines and sam local testing
This article will cover how you can use AWS CDK Pipelines and add a step with sam local based testing in your pipeline....
Read more >
SAM Local with Localstack - DEV Community ‍ ‍
Once we have this, we are ready to start the localstack in a docker container. You can do this by running, docker-compose up...
Read more >
AWS SAM in a Docker container - Entechlog
Validate SAM project locally · Invoke SAM project locally by running. sam local invoke --container-host host.docker.internal · Start Lambda ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found