It's time to leave the AWS Console behind and use code to define and deploy your Lambda function.
In this chapter, we'll:
You'll go from zero to infrastructure-as-code, and build a rock-solid foundation for the rest of the guide.
Make a new directory
mkdir terraform && cd terraform
Create this file to define your project:
# main.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
required_version = ">= 1.4.0"
}
provider "aws" {
region = "us-east-1" # Change this if you're in another region
}
Now let's define the Docker repository your Lambda will use:
# main.tf
resource "aws_ecr_repository" "ruby_lambda" {
name = "my-ruby-lambda"
}
This creates a private ECR repo named my-ruby-lambda
where we'll push your Docker image.