Skip to content

[WIP/Discussion] Add hot reload for python runtimes - #435

Closed
mijdavis2 wants to merge 1 commit into
aws:developfrom
mijdavis2:hot-loading-python
Closed

mijdavis2 wants to merge 1 commit into
aws:developfrom
mijdavis2:hot-loading-python

Conversation

@mijdavis2

Copy link
Copy Markdown
Contributor

Issue #, if available:
n/a

Description of changes:
Adds a "hot loader" for local development when using python runtimes.

Since python runtimes require a cp src_dir/* src_dir/build/ on each change (due to the flat dir constraint of the lambda framework), I initially made a wrapper around sam local start-api to watch and copy src files to the build dir on changes.

I started integrating the loader into the cli to make the wrapper unnecessary. If there's an interest in this feature, I'll keep working to productionize this. Otherwise, I don't want to waste the cycles.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sanathkr

Copy link
Copy Markdown

@mijdavis2 This feature is super cool and incredibly useful for Python devs

I think we can generalize this further into a separate sam build command and add a --watch flag to watch files and run build actions. You could have sam build --watch running in a separate terminal that continually rebuilds in background while you use sam local start-api in another terminal to test the function. I think this will be more powerful. Thoughts?

This PR makes three assumptions:

  1. Users have a build/ directory where Lambda function code files reside
  2. Py users want to always hot reload
  3. The only "build" action for Py users is copying files to the 'build/' directory.

By providing a separate sam build command, we can let user customize these assumptions. In this command, we can provide default implementation for all Lambda runtimes and allow users override default implementation by providing a makefile or bash script or an executable. This extension mechanism could also be CodeBuild Local (#402).

What do you think about this? If you like it, I am happy to collaborate with you on an RFC for the sam build command so we can get a clear set of requirements before building it out.

@sanathkr sanathkr added the stage/needs-feedback Needs feedback from the community (are you also interested in/experiencing this?) label May 31, 2018
@sanathkr

sanathkr commented May 31, 2018 •

Copy link
Copy Markdown

Similar in spirit to #195, #200

@sanathkr sanathkr added the blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days label Jun 28, 2018
@jfuss

jfuss commented Jul 6, 2018

Copy link
Copy Markdown
Contributor

There hasn't been any activity here in a while, so going to close the PR. Happy to reopen in the future though.

@jfuss jfuss closed this Jul 6, 2018
@pyk

pyk commented Apr 26, 2020

Copy link
Copy Markdown
Contributor

For those who get here from google search.

Here is alternative solution to enable hot reload on your python sam app:

Use watchmedo to watch any changes in your function.

For example:

watchmedo shell-command -p ".\Lambda*\*.py" -i ".\Lambda*\*.py.*" -R -W --command='sam build' .

This will rebuild your apps if there is any changes.

Then on another terminal tab, start the server:

sam local start-api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days stage/needs-feedback Needs feedback from the community (are you also interested in/experiencing this?)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants