↓Skip to main content
  1. 🔰Posts/
  2. 🗂️My Trainings/
  3. AWS Trainings and Certifications/
  4. Manage AWS Lambda functions with Terraform/

Terraform and Lambda - Required Arguments

📚 Part 2 of 2: "Terraform and Lambda" series.

The first and the most fundamental thing for the Lambda function to run is: the code.

Function name #

Handler #

Runtime #

Execution role #

Lambda Code Sources #

AWS Lambda supports three code sources when managed through Terraform:

  • Local ZIP file (filename)
  • ZIP stored in S3 (s3_bucket + s3_key)
  • Container image stored in ECR (image_uri)

Basic Function with Node.js #

# Package the Lambda function code
data "archive_file" "example" {
  type        = "zip"
  source_file = "${path.module}/lambda/index.js"
  output_path = "${path.module}/lambda/function.zip"
}

# Lambda function
resource "aws_lambda_function" "example" {
  filename      = data.archive_file.example.output_path
  function_name = "example_lambda_function"
  role          = aws_iam_role.example.arn
  handler       = "index.handler"
  code_sha256   = data.archive_file.example.output_base64sha256

  runtime = "nodejs24.x"
}

When using ECR, the Lambda runtime and handler are defined inside the container image, not in Terraform. Terraform only needs:

  • function_name
  • role
  • package_type = "Image"
  • image_uri

So the “runtime” and “handler” requirement applies only to ZIP‑based Lambdas.

Container Image Function #

resource "aws_lambda_function" "example" {
  function_name = "example_container_function"
  role          = aws_iam_role.example.arn
  package_type  = "Image"
  image_uri     = "${aws_ecr_repository.example.repository_url}:latest"

  image_config {
    entry_point = ["/lambda-entrypoint.sh"]
    command     = ["app.handler"]
  }

  memory_size = 512
  timeout     = 30

  architectures = ["arm64"] # Graviton support for better price/performance
}

More: Resource: aws_lambda_function

» Sources « #

» Disclaimer « #

This series draws heavily from Tamás Sallai’s Manage AWS Lambda functions with Terraform course on Udemy.

About the instructor
🌐 Website💼 LinkedIn

ℹ️Shared for educational purposes only, no rights reserved.

Series Overview: Terraform and Lambda

2 parts in this series. View full series →


RobK
Author
RobK
DevOps | Agile | AWS | Ansible | Terraform | GitHub Actions | Linux | Windows