Created
May 24, 2020 19:08
-
-
Save TanAlex/8a7cc751a5b9d4323bb59d17f016805c to your computer and use it in GitHub Desktop.
Terraform Snippet to deploy lambda@edge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "archive_file" "folder_index_redirect_zip" { | |
type = "zip" | |
output_path = "${path.module}/folder_index_redirect.js.zip" | |
source_file = "${path.module}/folder_index_redirect.js" | |
} | |
resource "aws_iam_role_policy" "lambda_execution" { | |
name_prefix = "lambda-execution-policy-" | |
role = aws_iam_role.lambda_execution.id | |
policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": [ | |
"logs:CreateLogStream", | |
"logs:PutLogEvents", | |
"logs:CreateLogGroup" | |
], | |
"Effect": "Allow", | |
"Resource": "*" | |
} | |
] | |
} | |
EOF | |
} | |
resource "aws_iam_role" "lambda_execution" { | |
name_prefix = "lambda-execution-role-" | |
description = "Managed by Terraform" | |
assume_role_policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": [ | |
"edgelambda.amazonaws.com", | |
"lambda.amazonaws.com" | |
] | |
}, | |
"Effect": "Allow", | |
"Sid": "" | |
} | |
] | |
} | |
EOF | |
tags = var.tags | |
} | |
resource "aws_lambda_function" "folder_index_redirect" { | |
description = "Managed by Terraform" | |
filename = "${path.module}/folder_index_redirect.js.zip" | |
function_name = "folder-index-redirect" | |
handler = "folder_index_redirect.handler" | |
source_code_hash = data.archive_file.folder_index_redirect_zip.output_base64sha256 | |
provider = aws.aws_cloudfront | |
publish = true | |
role = aws_iam_role.lambda_execution.arn | |
runtime = "nodejs10.x" | |
tags = var.tags | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment