I have defined a Lambda function with Terraform like this:
resource "aws_lambda_function" "this" {
filename = "${path.module}/src/existing-files-lambda.zip"
function_name = "ingest-existing-files-lambda"
role = aws_iam_role.lambda.arn
runtime = "python3.9"
timeout = 900
environment {
variables = {
source_bucket_arn = var.source_bucket_arn
destination_bucket_arn = var.destination_bucket_arn
}
}
}
resource "aws_iam_role" "lambda" {
name = "${var.prefix}-lambda-ingest"
path = "/service-role/"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Principal = { Service = "lambda.amazonaws.com" }
Action = "sts:AssumeRole"
}]
})
}
My python file is just this:
import os
def lambda_handler(event, context):
print('Hello world from Terraform')
return {
'statusCode': 200,
}
However, I am currently getting an error that:
│ Error: handler and runtime must be set when PackageType is Zip
│
│ with module.ingest_lambda.aws_lambda_function.this,
│ on ingest_lambda/main.tf line 8, in resource "aws_lambda_function" "this":
│ 8: resource "aws_lambda_function" "this" {
What do I put as handler here?
I already have runtime specified.