-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.tf
More file actions
49 lines (47 loc) · 2.19 KB
/
lambda.tf
File metadata and controls
49 lines (47 loc) · 2.19 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
#https://registry.terraform.io/providers/hashicorp/archive/latest/docs/data-sources/file
data "archive_file" "python_file" {
type = "zip"
source_dir = "${path.module}/lambda_function/"
output_path = "${path.module}/lambda_function/lambda_function.zip"
}
# #https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_object
#Upload Lambda code to source S3 bucket
resource "aws_s3_object" "lambda_zip" {
bucket = aws_s3_bucket.lambda_source.bucket
key = "lambda_function.zip"
source = data.archive_file.python_file.output_path
etag = filemd5(data.archive_file.python_file.output_path)
depends_on = [aws_s3_bucket_versioning.lambda_source]
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function
resource "aws_lambda_function" "lambda_run" {
s3_bucket = aws_signer_signing_job.build_signing_job.signed_object[0].s3[0].bucket
s3_key = aws_signer_signing_job.build_signing_job.signed_object[0].s3[0].key
source_code_hash = data.archive_file.python_file.output_base64sha256
function_name = var.name
role = aws_iam_role.lambda_role.arn
handler = "handler.lambda_handler"
runtime = "python3.12"
kms_key_arn = aws_kms_key.encryption.arn
environment {}
logging_config {
log_format = "JSON"
log_group = aws_cloudwatch_log_group.lambda_log.name
system_log_level = "INFO"
}
vpc_config {
subnet_ids = aws_subnet.private[*].id
security_group_ids = [aws_security_group.lambda.id]
}
tracing_config {
mode = "Active"
}
#https://docs.prismacloud.io/en/enterprise-edition/policy-reference/aws-policies/aws-general-policies/ensure-that-aws-lambda-function-is-configured-for-a-dead-letter-queue-dlq
dead_letter_config {
target_arn = aws_sqs_queue.dlq.arn
}
code_signing_config_arn = aws_lambda_code_signing_config.configuration.arn
reserved_concurrent_executions = 5
# Ensure the code signing config is created before the Lambda function
depends_on = [aws_lambda_code_signing_config.configuration, aws_signer_signing_job.build_signing_job, aws_iam_role_policy_attachment.lambda_policy_attachement]
}