Quick Start
Get up and running with sls.tf in 5 minutes
1. Add sls.tf to your project
Add sls.tf as a Git submodule inside your Terraform project:
git submodule add https://github.com/sls-tf/sls.tf.git modules/sls.tf
git submodule update --init --recursive 2. Create your Terraform root
Point the module at your existing serverless.yml:
main.tf
terraform {
required_version = ">= 1.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
module "serverless" {
source = "./modules/sls.tf"
config_path = "${path.root}/serverless.yml"
} 3. Write a minimal serverless.yml
serverless.yml
service: hello-world
provider:
name: aws
runtime: nodejs20.x
region: us-east-1
stage: dev
functions:
hello:
handler: index.handler
events:
- http:
path: /hello
method: get Prefer AWS SAM?
sls.tf reads AWS SAM templates too — a frequent choice for teams already using
sam local. Point config_path at your template.yaml and
set config_format = "sam"; the rest of the workflow is identical.
main.tf
module "serverless" {
source = "git::https://github.com/sls-tf/sls.tf.git?ref=v0.3.16"
config_path = "${path.root}/template.yaml"
config_format = "sam"
} template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Runtime: nodejs20.x
Timeout: 10
Resources:
Hello:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Events:
HelloApi:
Type: Api
Properties:
Path: /hello
Method: get
See the SAM template example for a complete walkthrough,
including Parameters and sam_template_parameters overrides.
4. Deploy
terraform init
terraform plan
terraform apply
Terraform will create the Lambda function, IAM execution role, API Gateway REST API, and all
required permissions — everything sls.tf infers from your serverless.yml.
Access outputs
After terraform apply, retrieve the API endpoint and function ARNs:
terraform output -json
# Example output:
# {
# "api_gateway_invoke_url": "https://abc123.execute-api.us-east-1.amazonaws.com/dev",
# "function_arns": { "hello": "arn:aws:lambda:us-east-1:..." },
# "function_names": { "hello": "hello-world-dev-hello" }
# } Next steps
- Configuration Guide — all available variables
- Outputs Reference — every value sls.tf exposes
- TypeScript Config — use
serverless.tsinstead - Basic Service Example — a complete worked example