-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Andriy Knysh <[email protected]> Co-authored-by: cloudpossebot <[email protected]> * Add submodule for creating Lambda@Edge functions * Add test for Lambda@Edge submodule * Ensure all tests run in parallel. * Fix `versions.tf` in `examples/complete` according to TFLint
- Loading branch information
Showing
18 changed files
with
863 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
alias = "us-east-1" | ||
} | ||
|
||
module "lambda_at_edge" { | ||
source = "../../modules/lambda@edge" | ||
|
||
enabled = local.enabled && var.lambda_at_edge_enabled | ||
|
||
functions = { | ||
# Just for the sake of a viewer-request example, inject a useless header into the request from the viewer to CF | ||
viewer_request = { | ||
source = [{ | ||
content = <<-EOT | ||
'use strict'; | ||
exports.handler = (event, context, callback) => { | ||
const { request } = event.Records[0].cf; | ||
request.headers['useless-header'] = [ | ||
{ | ||
key: 'Useless-Header', | ||
value: 'This header is absolutely useless.' | ||
} | ||
]; | ||
return callback(null, request); | ||
}; | ||
EOT | ||
filename = "index.js" | ||
}] | ||
runtime = "nodejs12.x" | ||
handler = "index.handler" | ||
event_type = "viewer-request" | ||
include_body = false | ||
}, | ||
# Add security headers to the request from CF to the origin | ||
origin_request = { | ||
source = [{ | ||
# https://aws.amazon.com/blogs/networking-and-content-delivery/adding-http-security-headers-using-lambdaedge-and-amazon-cloudfront/ | ||
content = <<-EOT | ||
'use strict'; | ||
exports.handler = (event, context, callback) => { | ||
//Get contents of response | ||
const response = event.Records[0].cf.response; | ||
const headers = response.headers; | ||
//Set new headers | ||
headers['strict-transport-security'] = [{key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubdomains; preload'}]; | ||
headers['content-security-policy'] = [{key: 'Content-Security-Policy', value: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'"}]; | ||
headers['x-content-type-options'] = [{key: 'X-Content-Type-Options', value: 'nosniff'}]; | ||
headers['x-frame-options'] = [{key: 'X-Frame-Options', value: 'DENY'}]; | ||
headers['x-xss-protection'] = [{key: 'X-XSS-Protection', value: '1; mode=block'}]; | ||
headers['referrer-policy'] = [{key: 'Referrer-Policy', value: 'same-origin'}]; | ||
//Return modified response | ||
callback(null, response); | ||
}; | ||
EOT | ||
filename = "index.js" | ||
}] | ||
runtime = "nodejs12.x" | ||
handler = "index.handler" | ||
event_type = "origin-response" | ||
include_body = false | ||
} | ||
} | ||
|
||
# A destruction delay is always enabled due to automated tests (see variable description for more information). | ||
destruction_delay = "20m" | ||
|
||
providers = { | ||
aws = aws.us-east-1 | ||
} | ||
|
||
context = module.this.context | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
region = "us-east-2" | ||
|
||
namespace = "eg" | ||
|
||
stage = "test" | ||
|
||
name = "cf-s3-cdn-lambda" # name needs to be shortened due to s3 bucket name length restrictions | ||
|
||
parent_zone_name = "testing.cloudposse.co" | ||
|
||
lambda_at_edge_enabled = true |
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
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
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
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
Oops, something went wrong.