Search code examples
amazon-web-servicesaws-sam-cli

Run AWS SAM Local on another port


I've been successful in running AWS SAM Local on my machine on port 3000 with this command:

sam local start-api

The documentation says there's a flag -d that runs the server in debug mode on a different port. I need to run this on port 8080. So I tried this:

sam local start-api -d 8080

And the server still starts up on 3000:

Mounting api.get_account (python3.6) at http://127.0.0.1:3000/account/{account_num} [GET]

Does anyone know what I'm doing wrong here? Thanks!


Solution

  • The -d (--debug-port) option refers to the port that you would connect a debugger to, not the port that the application listens on.

    So sam local start-api -d 8080 translates to "Start the application on the default port, and allow me to connect a debugger to port 8080".

    To have the application listen on a different port, use the -p (--port) option.

    You can of course use both. For example,

    sam local start-api -p 8080 -d 5858
    

    means "Start the application on port 8080, and allow me to connect a debugger on port 5858".