AWS SAM template.yaml Builder

Generate an AWS SAM template for serverless Lambda functions

Build a valid AWS SAM template.yaml with a Lambda function, runtime, handler, memory and timeout, environment variables, an optional API Gateway trigger, and CloudFormation outputs — copy or download for sam deploy.

What is the Transform line in a SAM template?

Transform: AWS::Serverless-2016-10-31 tells CloudFormation to process the SAM macro, which expands shorthand resources like AWS::Serverless::Function into full Lambda, IAM, and API Gateway resources at deploy time.

A working SAM template in seconds

AWS SAM lets you describe a serverless function in a compact YAML template that CloudFormation expands into Lambda, IAM, and API Gateway resources. The shorthand is powerful but indentation-sensitive, so this builder generates a syntactically correct template.yaml from a short form.

How it works

The tool emits the required AWSTemplateFormatVersion and the Transform: AWS::Serverless-2016-10-31 macro line, then a Globals block carrying the shared runtime, memory, and timeout. Your function becomes an AWS::Serverless::Function resource with its Handler and CodeUri. Environment variables are nested under Environment.Variables with values JSON-encoded so quotes and special characters stay valid YAML. Enabling the API trigger adds an Events entry of type Api with your chosen Path and Method, which SAM turns into a managed API Gateway route plus the invoke permission. Finally an Outputs section exposes the function ARN and, when an API exists, the constructed endpoint URL via !Sub.

Example and notes

A nodejs20.x function with handler index.handler, CodeUri: src/, and a get event on /hello is a complete hello-world API. Keep memory modest (128–512 MB) for simple handlers and raise it only if profiling shows CPU-bound work. After copying, run sam build then sam deploy --guided; the guided deploy walks you through stack name, region, and confirmation, and the outputs print your live endpoint.