How do I specify template parameters when running AWS SAM Local?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
When working with AWS SAM (Serverless Application Model) local, you might find yourself in situations where you need to pass parameters to your template. This is particularly relevant when you have dynamic configurations that change depending on the environment, such as development, testing, or production. Here, we'll explore how AWS SAM Local handles template parameters and how you can specify them effectively while running your serverless applications locally.
Introduction to AWS SAM
AWS SAM is an extension of AWS CloudFormation that provides a simplified way to define the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application. It offers a robust method for managing infrastructure as code for serverless applications, and SAM Local allows you to run and debug these applications on your local environment before deploying them to AWS.
Understanding Template `Parameters`
Template parameters in AWS SAM (and CloudFormation) provide a mechanism to pass custom values to your serverless stack at runtime. This enables you to create reusable and configurable SAM templates. `Parameters` can be specified for:
- DynamoDB table names
- API Gateway endpoint URLs
- Environment variables
- Resource IDs
- Other configuration details
Specifying Template `Parameters` in AWS SAM Local
While working with AWS SAM Local, you can specify template parameters in a way similar to how you'd handle them in a CloudFormation stack. Here's how:
1. Using a JSON/YAML Parameter File
A parameter file helps you define parameters separately from your SAM template file. This file is then referenced when invoking or starting your local serverless app.
Sample parameter file (`parameters.json`):
- Environment-Specific Configs: Use different parameter files for different environments, allowing you to easily switch configurations without modifying your `template.yaml` file.
- Security: Be cautious when embedding secrets within parameter files. Consider using AWS Secrets Manager for sensitive data.
- Testing: Parameter files can be valuable when writing tests that require different configurations.
Related reading
- How do I ssh to nodes in ACS Kubernetes cluster?
- How do I tell if my container is running inside a Kubernetes cluster?
- How do I terraform Amazon MSK topics?
- How do I test a module that depends on boto and an Amazon AWS service?
- How do I to forward example.com to www.example.com at godaddy for s3 hosted site?
- How do I update metadata for an existing Amazon S3 file?
- How do I use Amazon Cognito as user authentication for my website NOT mobile app
- How do I use AWS sdk definitions for TypeScript?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.