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

[SAM] Docker Perf on Mac & Root Proxy #15

Closed
metaskills opened this issue Mar 22, 2019 · 1 comment
Closed

[SAM] Docker Perf on Mac & Root Proxy #15

metaskills opened this issue Mar 22, 2019 · 1 comment
Labels
bug Something isn't working sam This issue or pull request already exists

Comments

@metaskills
Copy link
Member

metaskills commented Mar 22, 2019

Unfortunately, the SAM CLI project has a few needed enhancements and if you decide to do any local development via the sam local start-api command, it will need to be patched on your local machine. I used the commands below to find the two files needing patching.

$ which sam # Use directory info below in find command.
$ find /usr/local -name container.py | grep samcli
$ find /usr/local -name local_apigw_service.py | grep samcli

Here are the issues we have created on the SAM CLI project. Details on the patches below.

Docker Volume Mount Performance on Mac

If you are on a Mac, Docker has a known performance issue when sharing volumes due to the overhead of keeping files in sync. This performance issue means your Rails application could take ~60 seconds to load in development. Thankfully, Docker has tooling in place to help.

Once you found the correct container.py file, make this change below to tell the Docker SDK to mount the volume with both the ro (read-only) option and delegated consistency mode.

@@ -95,7 +95,7 @@
                     # https://docs.docker.com/storage/bind-mounts
                     # Mount the host directory as "read only" inside container
                     "bind": self._working_dir,
-                    "mode": "ro"
+                    "mode": "ro,delegated"
                 }
             },
             # We are not running an interactive shell here.

Fixing Root SAM Local Proxy Paths

We need our API Gateway to use both a root path and a greedy proxy path to forward to Rails in development. SAM has a feature compatibility bug where it forces static file hosting on the root path. Once you found the correct local_apigw_service.py file, make the change below to disable static public directory assets on the root path. Don't worry, Rails & Rack will serve your static files automatically instead.

@@ -71,7 +71,7 @@
         """

         self._app = Flask(__name__,
-                          static_url_path="",  # Mount static files at root '/'
+                          static_url_path=None,  # Mount static files at root '/'
                           static_folder=self.static_dir  # Serve static files from this directory
                           )
@metaskills metaskills added docs Shared in Issues or needed! sam This issue or pull request already exists bug Something isn't working labels Mar 22, 2019
@metaskills metaskills removed the docs Shared in Issues or needed! label Jun 13, 2019
@metaskills
Copy link
Member Author

This has been resolved (aws/aws-sam-cli#1046) and is also moot when we use our own Docker images like this Cookiecutter (https://technology.customink.com/blog/2020/03/13/using-aws-sam-cookiecutter-project-templates-to-kickstart-your-ambda-projects/) in future Lamby templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sam This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

1 participant