Forrest logo
back to the sam tool

sam:tldr:55dcf

sam: Run your serverless application locally.
$ sam local start-api
try on your machine

The sam local start-api command is used to start a local API Gateway to test and run serverless applications developed using AWS SAM (Serverless Application Model) locally on your machine.

Here's what the command does:

  1. sam local: The first part of the command is sam local, which invokes the AWS SAM CLI (Command Line Interface). This CLI allows developers to build, test, and deploy serverless applications locally.

  2. start-api: The start-api command is a subcommand of the AWS SAM CLI, specifically used to start a local API Gateway.

When you run sam local start-api, it performs the following actions:

  1. It reads the configuration defined in the template.yaml file present in the current directory. This file describes the serverless application's AWS resources and mappings for the API Gateway.

  2. It creates a local instance of the API Gateway using Docker containers or a native local API Gateway implementation, depending on your setup.

  3. The local API Gateway listens on a default or specified port (usually 3000) on your local machine.

  4. It deploys the serverless application and maps the necessary routes and methods defined in the template.yaml file to appropriate Lambda functions.

  5. Finally, it provides you with a local URL that you can use to interact with the APIs through tools like cURL or a web browser, allowing you to test your APIs and see the responses, just as if you were using API Gateway in the AWS cloud.

By using sam local start-api, developers can iterate and debug their serverless applications locally without the need to deploy them to the AWS cloud. This accelerates development and enables easier testing and debugging of serverless APIs.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the sam tool