Supported Resource Types

AWS resources that sls.tf can create from your serverless configuration

Overview

sls.tf creates AWS resources from two sources: the functions: block (Lambda, IAM roles, event wiring) and the resources: block (custom infrastructure). The resource_types variable lets you restrict which CloudFormation resource types from the resources: section get materialised.

Restrict resource creation

module "serverless" {
  source      = "./modules/sls.tf"
  config_path = "${path.root}/serverless.yml"

  # Only create Lambda functions and DynamoDB tables from the resources: section.
  # API Gateway, S3 event wiring, etc. are always created regardless.
  resource_types = [
    "AWS::Serverless::Function",
    "AWS::DynamoDB::Table",
  ]
}

Always-Created Resources

These resources are created whenever the corresponding events or functions are present, regardless of the resource_types setting:

aws_lambda_function

One per function in the functions: block.

aws_iam_role

Execution role per function with CloudWatch Logs permissions.

aws_iam_role_policy

Custom inline policy when iamRoleStatements are defined.

aws_api_gateway_rest_api

Created when any function has an http event.

aws_api_gateway_stage

Deployed stage for the REST API.

aws_s3_bucket_notification

Trigger wiring for s3 events.

aws_cloudwatch_event_rule

Created for schedule and eventBridge events.

aws_lambda_event_source_mapping

Created for stream (DynamoDB/Kinesis) and sqs events.

Custom Resources (resources: section)

Resources defined in the resources: block using CloudFormation syntax. These are gated by the resource_types variable.

AWS::S3::Bucket

Creates aws_s3_bucket. Exposes custom_s3_bucket_ids and custom_s3_bucket_arns outputs.

AWS::DynamoDB::Table

Creates aws_dynamodb_table. Exposes custom_dynamodb_table_names and custom_dynamodb_table_arns outputs.

AWS::SNS::Topic

Creates aws_sns_topic. Exposes custom_sns_topic_names and custom_sns_topic_arns outputs.

AWS::SQS::Queue

Creates aws_sqs_queue. Exposes names, ARNs, and URLs.

AWS::CloudFront::Distribution

Creates aws_cloudfront_distribution. Exposes IDs, ARNs, and domain names.

AWS::Serverless::Function

SAM function shorthand — treated equivalently to a Serverless Framework function entry.

Lambda@Edge

Functions with cloudFront events automatically create aws_cloudfront_distribution resources. These are tracked separately under the lambda_edge_distribution_* outputs.

Lambda@Edge example

functions:
  viewerRequest:
    handler: edge/viewerRequest.handler
    events:
      - cloudFront:
          eventType: viewer-request
          origin:
            DomainName: my-bucket.s3.amazonaws.com

AWS SAM Support

Set config_format = "sam" to use an AWS SAM template.yaml. Pass parameter overrides via sam_template_parameters:

module "serverless" {
  source        = "./modules/sls.tf"
  config_path   = "${path.root}/template.yaml"
  config_format = "sam"

  sam_template_parameters = {
    Environment = "production"
    TableName   = "my-table-prod"
  }

  # Only materialise functions; DynamoDB table managed elsewhere
  resource_types = ["AWS::Serverless::Function"]
}