AWS SAM
template parameters
local development
serverless applications
cloud computing

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.

Practice system design

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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.