Lokales Testen und Debuggen mit SAM CLI
Führen Sie Ihre Serverless Functions vor dem Deployment auf Ihrem eigenen Rechner aus und debuggen Sie sie dort. Verwenden Sie sam local, um Functions aufzurufen, API Gateway zu emulieren und schnell zu iterieren.
Lokales Testen und Debuggen mit SAM CLI ist eine kostenlose Serverless Backend with AWS Lambda & API Gateway-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Serverless Backend with AWS Lambda & API Gateway-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Serverless Backend with AWS Lambda & API Gateway-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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.jsonGenerating 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.jsonEmulating 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/helloEnvironment Variables Locally
Supply env vars via a JSON file so local runs match what the function expects.
sam local invoke HelloFunction \
--env-vars env.jsonHot 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 5858Validating the Template
Catch template errors before deploying with a quick validation command.
sam validate --lintViewing Logs
After a deploy you can tail CloudWatch logs from the terminal, filtering by function.
sam logs -n HelloFunction --tailLimitations 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 invokeruns a single functionsam local start-apiemulates API Gateway- Generate events, supply env vars, and attach a debugger
sam validatecatches template errors early- Local mode has limits — verify in a real stage before prod
Häufig gestellte Fragen
Ist die Lektion „Lokales Testen und Debuggen mit SAM CLI“ kostenlos?
Ja — der vollständige Text von „Lokales Testen und Debuggen mit SAM CLI“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Serverless Backend with AWS Lambda & API Gateway-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Serverless Backend with AWS Lambda & API Gateway-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Lokales Testen und Debuggen mit SAM CLI“?
Führen Sie Ihre Serverless Functions vor dem Deployment auf Ihrem eigenen Rechner aus und debuggen Sie sie dort. Verwenden Sie sam local, um Functions aufzurufen, API Gateway zu emulieren und schnell… Du übst Serverless Backend with AWS Lambda & API Gateway mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Serverless Backend with AWS Lambda & API Gateway zu starten?
Keine Vorkenntnisse erforderlich. Serverless Backend with AWS Lambda & API Gateway auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Lokales Testen und Debuggen mit SAM CLI“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Serverless Backend with AWS Lambda & API Gateway-Lektion Code schreiben und ausführen?
Ja. Jede Serverless Backend with AWS Lambda & API Gateway-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Einführung in AWS SAM
- Serverless-Ressourcen definieren
- SAM-Anwendungen deployen
- Lokales Testen und Debuggen mit SAM CLI