- Welcome my DevOps blog./
- 🔰Posts/
- 🗂️My Trainings/
- AWS Trainings and Certifications/
- Manage AWS Lambda functions with Terraform/
- Terraform and Lambda - Required Arguments/
Terraform and Lambda - Required Arguments
📚 Part 2 of 2: "Terraform and Lambda" series.
·228 words·2 mins

Table of Contents
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_namerolepackage_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 |
