0Pricing
Serverless Backend with AWS Lambda & API Gateway · レッスン

SAM CLIによるローカルテストとデバッグ

デプロイ前に自分のマシンでサーバーレス関数を実行・デバッグします。sam localで関数を呼び出し、API Gatewayをエミュレートしながら迅速に反復する方法を学びます。

「SAM CLIによるローカルテストとデバッグ」はCoddyKit上の無料Serverless Backend with AWS Lambda & API Gatewayレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはServerless Backend with AWS Lambda & API Gateway学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Serverless Backend with AWS Lambda & API Gatewayコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Why Test Locally?

Deploying to AWS just to test a change is slow. The SAM CLI emulates Lambda and API Gateway locally using Docker, so you can iterate in seconds.

Prerequisites

Local invocation needs:

  • Docker running
  • The SAM CLI installed
  • A valid template.yaml

Invoking a Single Function

Run one function with a test event payload.

sam local invoke HelloFunction --event events/event.json

Generating Sample Events

SAM can generate realistic event payloads for many AWS sources, saving you from writing them by hand.

sam local generate-event apigateway aws-proxy > events/event.json

Emulating the API

Start a local HTTP server that mimics API Gateway, routing requests to your functions.

sam local start-api
# then: curl http://localhost:3000/hello

Environment Variables Locally

Supply env vars via a JSON file so local runs match what the function expects.

sam local invoke HelloFunction \
  --env-vars env.json

Hot Reload During Development

SAM watches your source: when you save a change, the next request uses the new code without restarting the local API, keeping the feedback loop tight.

Step Debugging

Attach a debugger by passing a debug port. Your IDE connects to it so you can set breakpoints inside the running container.

sam local invoke HelloFunction -d 5858

Validating the Template

Catch template errors before deploying with a quick validation command.

sam validate --lint

Viewing Logs

After a deploy you can tail CloudWatch logs from the terminal, filtering by function.

sam logs -n HelloFunction --tail

Limitations of Local Emulation

Local mode is great for logic, but it cannot perfectly mirror IAM permissions, real network latency, or managed services like DynamoDB. Always run an integration test in a real AWS stage before production.

Quick Check

Test your SAM CLI knowledge.

Recap

You learned local development with SAM:

  • sam local invoke runs a single function
  • sam local start-api emulates API Gateway
  • Generate events, supply env vars, and attach a debugger
  • sam validate catches template errors early
  • Local mode has limits — verify in a real stage before prod

よくある質問

「SAM CLIによるローカルテストとデバッグ」レッスンは無料ですか?

はい。「SAM CLIによるローカルテストとデバッグ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Serverless Backend with AWS Lambda & API Gatewayコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Serverless Backend with AWS Lambda & API Gatewayコースには全4レッスンが含まれています。

「SAM CLIによるローカルテストとデバッグ」で何を学びますか?

デプロイ前に自分のマシンでサーバーレス関数を実行・デバッグします。sam localで関数を呼び出し、API Gatewayをエミュレートしながら迅速に反復する方法を学びます。 ブラウザで直接実行するハンズオンコードでServerless Backend with AWS Lambda & API Gatewayを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Serverless Backend with AWS Lambda & API Gatewayを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのServerless Backend with AWS Lambda & API Gatewayは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「SAM CLIによるローカルテストとデバッグ」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このServerless Backend with AWS Lambda & API Gatewayレッスンでコードを書いて実行できますか?

はい。すべてのServerless Backend with AWS Lambda & API Gatewayレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. AWS SAM入門
  2. サーバーレスリソースの定義
  3. SAMアプリケーションのデプロイ
  4. SAM CLIによるローカルテストとデバッグ
← Serverless Backend with AWS Lambda & API Gatewayに戻る