Skip to content

Commit b4a238d

Browse files
committed
Removed Lambda@Edge integration
1 parent ab298bf commit b4a238d

File tree

4 files changed

+25
-110
lines changed

4 files changed

+25
-110
lines changed

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Local .terraform directories
2+
.terraform/
3+
4+
# Compiled .tfstate files
5+
*.tfstate
6+
*.tfstate.*
7+
8+
# Logs
9+
*.log
10+
11+
# Ignore Mac .DS_Store files
12+
.DS_Store
13+
14+
# Ignored vscode files
15+
.vscode/
16+
17+
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
18+
# .tfvars files are managed as part of configuration and so should be included in
19+
# version control.
20+
#
21+
# example.tfvars
22+
23+
# Ignore aws credentials
24+
.aws/

lambda/cloudfront_folder_index_redirect.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
-1.07 KB
Binary file not shown.

main.tf

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,6 @@ resource "aws_cloudfront_distribution" "website_cdn_root" {
181181
}
182182
}
183183

184-
lambda_function_association {
185-
event_type = "origin-request" # To use the url redirection Lambda@Edge, the trigger must be defined for the origin-request event
186-
lambda_arn = aws_lambda_function.website_lambda_redirect_folder_index.qualified_arn
187-
}
188184
}
189185

190186
restrictions {
@@ -337,76 +333,4 @@ resource "aws_route53_record" "website_cdn_redirect_record" {
337333
zone_id = aws_cloudfront_distribution.website_cdn_redirect.hosted_zone_id
338334
evaluate_target_health = false
339335
}
340-
}
341-
342-
## Lambda
343-
# Generates IAM policy in JSON format for the IAM role that will be attached to the Lambda Function
344-
data "aws_iam_policy_document" "lambda_assume_role_policy" {
345-
statement {
346-
actions = ["sts:AssumeRole"]
347-
principals {
348-
type = "Service"
349-
identifiers = ["lambda.amazonaws.com", "edgelambda.amazonaws.com"]
350-
}
351-
}
352-
}
353-
354-
# Create the IAM role that will be attached to the Lambda Function and associate it with the previously created policy
355-
resource "aws_iam_role" "lambda_exec_role_cloudfront_redirect" {
356-
name = "LambdaExecRoleCloudFrontRedirect"
357-
path = "/services-roles/"
358-
359-
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role_policy.json
360-
361-
tags = {
362-
ManagedBy = "terraform"
363-
Changed = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
364-
}
365-
366-
lifecycle {
367-
ignore_changes = [tags]
368-
}
369-
}
370-
371-
# Attach the predefined AWSLambdaBasicExecutionRole to grant permission to the Lambda execution role to see the CloudWatch logs generated when CloudFront triggers the function.
372-
resource "aws_iam_role_policy_attachment" "lambda_exec_role_cloudwatch_policy" {
373-
role = aws_iam_role.lambda_exec_role_cloudfront_redirect.name
374-
policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
375-
}
376-
377-
# Generates a ZIP archive from the Javascript script
378-
data "archive_file" "cloudfront_folder_index_redirect_code" {
379-
type = "zip"
380-
source_file = "${path.module}/lambda/cloudfront_folder_index_redirect.js"
381-
output_path = "${path.module}/lambda/cloudfront_folder_index_redirect.js.zip"
382-
}
383-
384-
# Creates the Lambda Function
385-
resource "aws_lambda_function" "website_lambda_redirect_folder_index" {
386-
provider = aws.us-east-1 # Lambda@Edge invoked by CloudFront must reside in us-east-1
387-
function_name = "cloudfront-folder-index-redirect"
388-
description = "Implements Default Directory Indexes in Amazon S3-backed Amazon CloudFront Origins"
389-
handler = "cloudfront_folder_index_redirect.handler"
390-
filename = data.archive_file.cloudfront_folder_index_redirect_code.output_path
391-
source_code_hash = data.archive_file.cloudfront_folder_index_redirect_code.output_base64sha256
392-
role = aws_iam_role.lambda_exec_role_cloudfront_redirect.arn
393-
runtime = "nodejs10.x"
394-
timeout = "30" # 30 seconds is the MAXIMUM allowed for functions triggered by a CloudFront event
395-
publish = true
396-
397-
tags = {
398-
ManagedBy = "terraform"
399-
Changed = formatdate("YYYY-MM-DD hh:mm ZZZ", timestamp())
400-
}
401-
402-
lifecycle {
403-
ignore_changes = [tags]
404-
}
405-
}
406-
407-
# Please note that `terraform destroy` may fail as it is not possible to delete a Lambda replicated function. If that's the case, the error message will be similar to:
408-
# Error: Error deleting Lambda Function: InvalidParameterValueException: Lambda was unable to delete arn:aws:lambda:us-east-1:<redacted>:function:cloudfront-folder-index-redirect:4 because it is a replicated function. Please see our documentation for Deleting Lambda@Edge Functions and Replicas.
409-
# { Message_: "Lambda was unable to delete arn:aws:lambda:us-east-1:<redacted>:function:cloudfront-folder-index-redirect:4 because it is a replicated function. Please see our documentation for Deleting Lambda@Edge Functions and Replicas."}
410-
411-
# The function will be automatically deleted a few hours after you have removed the last association for the function from all of your CloudFront distributions
412-
# Documentation: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-delete-replicas.html
336+
}

0 commit comments

Comments
 (0)