Вы можете сжать все файлы, необходимые для лямбды, и предоставить этот zip в качестве входных данных для лямбда-функции. Голый минимальный пример:
file structure:
-zippedfile.zip
--pytonfile.py
--helperLib.py
-main.tf
-variables.tf
********* pythonfile.py:
import helperLib
def lambda_function(event, context):
print("this is a cool lambda function!")
********* variables.tf:
variable "aws_access_key_id" {
default = ""
}
variable "aws_secret_access_key" {
default = ""
}
variable "aws_region" {
default = ""
}
********* main.tf:
provider "aws" {
access_key = "${var.aws_access_key_id}"
secret_key = "${var.aws_secret_access_key}"
region = "${var.aws_region}"
profile = "default"
}
resource "aws_iam_role" "lambda_exe_role" {
name = "lambda_exe_role"
path = "/"
description = "Allows Lambda Function to call AWS services on your behalf."
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_lambda_function" "lambda_function" {
role = "${aws_iam_role.lambda_exe_role.arn}"
handler = "pythonfile.lambda_function"
runtime = "python3.7"
filename = "zippedfile.zip"
function_name = "cool_lambda"
source_code_hash = "${base64sha256(file("zippedfile.zip"))}"
}