51 lines
1.4 KiB
HCL
51 lines
1.4 KiB
HCL
resource "aws_lambda_layer_version" "libraries" {
|
|
description = "Python3 requests library"
|
|
depends_on = [data.archive_file.layer1]
|
|
filename = "lambda-layer1.zip"
|
|
layer_name = "Python3RequestsLibrary"
|
|
|
|
compatible_runtimes = ["python3.12"]
|
|
}
|
|
|
|
data "archive_file" "layer1" {
|
|
source_dir = "lambda-layer1"
|
|
type = "zip"
|
|
output_path = "lambda-layer1.zip"
|
|
}
|
|
|
|
data "archive_file" "function1" {
|
|
source_file = "function.py"
|
|
type = "zip"
|
|
output_path = "function1.zip"
|
|
}
|
|
|
|
resource "aws_lambda_function" "myFunction" {
|
|
description = "Lambda layer test"
|
|
filename = data.archive_file.function1.output_path
|
|
source_code_hash = data.archive_file.function1.output_base64sha256
|
|
function_name = "TestFunction"
|
|
role = aws_iam_role.lambda-role1.arn
|
|
handler = "function.lambda_handler"
|
|
runtime = "python3.12"
|
|
architectures = ["arm64"]
|
|
layers = [aws_lambda_layer_version.libraries.arn]
|
|
}
|
|
|
|
resource "aws_iam_role" "lambda-role1" {
|
|
name = "TestFunctionRole"
|
|
assume_role_policy = jsonencode(
|
|
{
|
|
"Version" : "2012-10-17",
|
|
"Statement" : [
|
|
{
|
|
"Effect" : "Allow",
|
|
"Principal" : {
|
|
"Service" : "lambda.amazonaws.com"
|
|
},
|
|
"Action" : "sts:AssumeRole"
|
|
}
|
|
]
|
|
}
|
|
)
|
|
managed_policy_arns = ["arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"]
|
|
} |