aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.52k stars 1.17k forks source link

Bug: sam build --use-container doesn't work with WSL2 `networkingMode=mirrored` #6017

Open mew1033 opened 1 year ago

mew1033 commented 1 year ago

Description:

WSL2 just introduced a new networking mode: networkingMode=mirrored. It's awesome. Fixes a lot of problems people have with using WSL while connected to a corporate VPN. https://devblogs.microsoft.com/commandline/windows-subsystem-for-linux-september-2023-update/ However, there is something wrong with binding ports in docker when this new method is set. It makes it impossible to sam build in a container. It errors out indicating the port is already in use. There's a (IMO, dumb) workaround that gets sam build working again: https://github.com/microsoft/WSL/issues/10494#issuecomment-1734567875 However, you have to add every port, separated by commas, to the ignoredPorts config item.

This is definitely a WSL issue. However, it'd be nice if we could specify which ports sam uses with docker while building to make it easier to apply this workaround. Right now, the values are listed here: https://github.com/aws/aws-sam-cli/blob/c5b9b1e399a1e5c938ef72934a14ede934e17bac/samcli/local/docker/container.py#L124-L125

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Windows 11 (22621.2361)
  2. sam --version: 1.97.0
  3. AWS region: us-west-2
sriram-mv commented 1 year ago

This is definitely a WSL issue. However, it'd be nice if we could specify which ports sam uses with docker while building to make it easier to apply this workaround. Right now, the values are listed here:

The ports are chosen at random between 5000-9000 so that you could run multiple sam local invokes, start-api, start-lambda etc in parallel. There is no certain set of ports that you could allow. However when you setup debugging, there is a port number that you can pass in the arguments which could be allowlisted.

mew1033 commented 1 year ago

The ports are chosen at random between 5000-9000 so that you ...

While I appreciate being able to run multiple sam commands in parallel, it's those 4000 ports I'd like to be able to customize. On my personal machine, I don't ever run enough simultaneous sam commands to need 4000 ports. I'd love it if I could customize that range.

sriram-mv commented 1 year ago

Interesting, an override of the behavior could be something that is supported. Happy to accept a proposal/PR on this one!