
Learn how Terraform handles AWS Lambda infrastructure by defining resources, data sources, and outputs, using plan, apply, and destroy to deploy and update stacks.
Explain packaging and referencing AWS Lambda function code in Terraform using the high five data source, via inline, file interpolation, or directory approaches with hashing.
Learn how to name AWS Lambda functions in Terraform to avoid function name clashes across regions and modules, using the random_id resource and string interpolation for unique, descriptive deployment names.
Configure the Lambda handler in Terraform by specifying the entry point inside the zip, using a file name, or defining a directory, enabling multiple functions from one package.
The runtime is the software environment for a lambda function, defining language and version. JavaScript runtimes follow a deprecation cycle with long-term support and active versions, requiring migrations before retirement.
Define the execution role to grant a Lambda function access to resources like S3 via a permissions policy and a trust (assume role) policy, using Terraform.
Terraform manages the fixed log group /aws/lambda/<function> and its log streams, enabling retention configuration and avoiding the race with Lambda's automatic log group creation.
Use the Terraform environment block to define environment variables for AWS Lambda, passing values like bucket names and resource identifiers; prefer string interpolation to reduce errors.
Allocate lambda memory from 128 megabytes to over three gigabytes, defaulting to 128 megabytes, and monitor max memory usage; understand how memory affects cpu, duration, and cost.
Set AWS Lambda timeouts based on normal execution time using CloudWatch duration reports, accounting for cold starts up to 15 minutes and default 3 seconds.
Explore reserved concurrency in AWS Lambda, defining a min and max pool to control how many function instances run and prevent other functions from running out of capacity.
Configure terraform to run npm as part of the state refresh, installing dependencies from package.json and package-lock.json into node_modules for the lambda.
Explore lambda function attributes, especially the ARVN, the identifier and its version. See how Terraform wires lambda with API gateway, lambda@edge, S3, and DynamoDB for event-driven workflows.
Over the years, AWS Lambda added support for ever finer control of how the functions work. That resulted in more than 2 dozen configuration options and that makes it hard to see what is important and what is just for a specific use-case. And even for seemingly straightforward ones there are usually not-so-obvious consequences.
For example, deploying a Lambda function and removing it by default leaves all its logs stored in CloudWatch Logs forever. Or memory setting is tied to CPU so adding more RAM also makes the function run faster even if it does not use it at all.
This course is a systematic view on how to best deploy and configure Lambda functions with Terraform. You'll learn about the important arguments and the best practices for each of them and a detailed discussion of what they change.
What you'll learn in this course
We'll start with a quick introduction to Terraform and how to set it up with AWS. Then we'll look into one argument at a time and see what it does.
Install and configure Terraform for AWS
Basics of a tf file
Required arguments (code, name, handler, runtime, role)
Optional arguments (log group, environment variables, memory, timeout, reserved concurrency)
Integrate external programs with Terraform (for example, npm install)
Lambda attributes