-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
57 lines (50 loc) · 2.52 KB
/
main.tf
File metadata and controls
57 lines (50 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#----------------------------------------------------------------------------
# Variables
#----------------------------------------------------------------------------
data "aws_caller_identity" "current" {}
#----------------------------------------------------------------------------
# Files zipping
#----------------------------------------------------------------------------
provider "archive" {}
data "archive_file" "lambda_zip" {
type = "zip"
source_file = "${path.module}/lambda-functions/example/index.py"
output_path = "${path.module}/lambda-functions/example/index.zip"
}
#----------------------------------------------------------------------------
# Lambda Prisma SDK Layer for Python 3.11
#----------------------------------------------------------------------------
resource "aws_s3_object" "prisma-layer-python3-11" {
bucket = var.s3_bucket
key = "prisma/prisma-py3.11-layer.zip"
source = "prisma/prisma-py3.11-layer.zip"
source_hash = filebase64sha256("${path.module}/prisma/prisma-py3.11-layer.zip")
}
resource "aws_lambda_layer_version" "prisma_layer" {
depends_on = [aws_s3_object.prisma-layer-python3-11]
compatible_runtimes = ["python3.11"]
layer_name = "prisma-layer"
description = "prisma library for Python 3.11"
compatible_architectures = ["x86_64"]
source_code_hash = filebase64sha256("${path.module}/layers/prisma/prisma-py3.11-layer.zip")
s3_bucket = var.s3_bucket
s3_key = "prisma/prisma-py3.11-layer.zip"
}
### Do the same with the rest of the layers ###
#----------------------------------------------------------------------------
# Lambda function, adjust the zip file accordingly, ensure that you zip the
# folder with your codes in index.py inside
#----------------------------------------------------------------------------
resource "aws_lambda_function" "lambda_function" {
filename = data.archive_file.lambda_zip.output_path
function_name = var.name
description = var.description
role = var.iam_role
handler = "index.lambda_handler"
timeout = var.timeout
memory_size = var.memory
reserved_concurrent_executions = -1
runtime = "python3.11"
source_code_hash = data.archive_file.lambda_zip.output_base64sha256
layers = [aws_lambda_layer_version.prisma_layer.arn] # Add multiple layers
}