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 start-api detached mode

See original GitHub issue

Describe your idea/feature/enhancement

Allow sam local start-api to run detached

Proposal

While SAM is great for local development it can fall short for CI or even test commands. In order to run tests automatically against my api-gateway I need to run sam local start-api this command continues running until I press Ctrl-C. This works well for local development but I would like to script this out into a CI that will allow me to run integration tests without deploying to aws.

Things to consider:

  1. Will this require any updates to the SAM Spec

    • No, as far as I know, this should require any updates to the spec.
  2. Additional arguments/commands

    • By adding a detached mode that also means there must be a non-interrupt way to stop the api. I suggest sam local stop-api as a way to stop the api. This command would be dependent on the directory and template that is running and thus the running instance would be a singleton.
    • I would suggest -d as this would follow the docker command scheme and be more familiar to developers.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:26
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
ghostcommented, May 21, 2020

Any updates on this?

2reactions
jonowhitecommented, Jul 20, 2021

I think this would be really helpful. I have similar use cases, my current method I am testing (which might be a little dodgy) is to send the sam command to the background and redirect all logs to prevent interference.

sam local start-api  > /dev/null 2>&1 &

This keeps the local API active while retaining control of the shell. So you could run it multiple times, or re-use the shell to run tests against the local API.

Potential issue when it comes to stopping the background processes if you have multiple running and need to be careful with which you kill.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sam local start-api detached mode · Issue #1012 - GitHub
In order to run tests automatically against my api-gateway I need to run sam local start-api this command continues running until I press...
Read more >
sam local start-api - AWS Serverless Application Model
Allows you to run your serverless application locally for quick development and testing. When you run this command in a directory that contains...
Read more >
sam local start-api - Fig.io
Sets up a local endpoint you can use to test your API. ... When specified, Lambda function will start in debug mode and...
Read more >
Invoking Lambda functions Locally with AWS SAM
If you don't know about docker -d means docker runs the container in detached mode. -p means mapping ports to 8000 in the...
Read more >
How to run sam local start-api - CircleCI Discuss
When I run sam local start-api in the jbo, I always get Build was canceled. My configuration is like this. Main purpose is...
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