Skip to content

Commit

Permalink
correct rootdomain vs sitedomain, use site domain internal to ckan
Browse files Browse the repository at this point in the history
  • Loading branch information
duttonw committed Jul 5, 2023
1 parent bdbcb3e commit 9758641
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cloudfront.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
register: acmUsEast1

- set_fact:
LambdaAtEdgeViewerRequestVersion: "{{ lambdaAtEdgeStack.ansible_facts.cloudformation[lambdaAtEdgestack_name].stack_outputs.VersionedLambdaFunction48e660f32023 }}"
LambdaAtEdgeViewerRequestVersion: "{{ lambdaAtEdgeStack.ansible_facts.cloudformation[lambdaAtEdgestack_name].stack_outputs.VersionedLambdaFunction48e660f32023b }}"
LambdaAtEdgeOriginRequestVersion: "{{ lambdaAtEdgeStack.ansible_facts.cloudformation[lambdaAtEdgestack_name].stack_outputs.LambdaEdgeOriginFunctionVersion9cd5bfa }}"
ACMCertificateARNForUsEast1: "{{ acmUsEast1.ansible_facts.cloudformation[acm_stack_name].stack_outputs.AcmCert }}"

Expand Down
22 changes: 11 additions & 11 deletions templates/cloudfront-lambdaAtEdge.cfn.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Description: Cloudfront Lambda At Edge for fronting an application.
Parameters:
RootDomain:
Description: Base domain to ensure alt domains are not allowed through
SiteDomain:
Description: Side domain to ensure alt domains are not allowed through
Type: String
Environment:
Description: Stack environment eg DEV, TRAINING
Expand Down Expand Up @@ -65,7 +65,7 @@ Resources:
Handler: index.handler
Timeout: 5

LambdaEdgeFunction48e660f2023:
LambdaEdgeFunction48e660f2023b:
Type: 'AWS::Lambda::Function'
Properties:
Code: #see files/cloudfrontLambda.js for human readable code (remove comments when updating inline js
Expand All @@ -82,13 +82,13 @@ Resources:
});
request.querystring = querystring.stringify(sortedParams);
let queryStringOutput = request.querystring ? '?' + request.querystring : ''
let wwwDomain = 'www.${RootDomain}'
if (request.headers.host[0].value !== wwwDomain) {
let siteDomain = '${SiteDomain}'
if (request.headers.host[0].value !== siteDomain) {
let redirect = {
status: '301',
statusDescription: `Redirecting to www domain`,
statusDescription: `Redirecting to site domain`,
headers: {
location: [{ key: 'Location', value: 'https://' + wwwDomain + request.uri + queryStringOutput }],
location: [{ key: 'Location', value: 'https://' + siteDomain + request.uri + queryStringOutput }],
"access-control-allow-origin": [{ key: "Access-Control-Allow-Origin", value: "*" }],
"access-control-allow-methods": [{ key: "Access-Control-Allow-Methods", value: "POST, PUT, GET, DELETE, OPTIONS" }],
"access-control-allow-headers": [{ key: "Access-Control-Allow-Headers", value: "X-CKAN-API-KEY, Authorization, Content-Type" }]
Expand Down Expand Up @@ -137,10 +137,10 @@ Resources:

# #versions are hard coded, if you need two versions, leave the old one in, but be aware that cloudformation does not like having two versions which are the same so it might get cranky.
# #current version as of 6/9/2023
VersionedLambdaFunction48e660f32023: #change name if changing lambda code and update cloudfront link
VersionedLambdaFunction48e660f32023b: #change name if changing lambda code and update cloudfront link
Type: 'AWS::Lambda::Version'
Properties:
FunctionName: !Ref LambdaEdgeFunction48e660f2023
FunctionName: !Ref LambdaEdgeFunction48e660f2023b

LambdaOriginFunctionVersion9cd5bfa:
Type: 'AWS::Lambda::Version'
Expand Down Expand Up @@ -173,8 +173,8 @@ Outputs:
#don't forget add the new version to output the value for cross region referencing. Note cfn import's don't work cross region so we can't lock it sadly

#current version as of 6/9/2023
VersionedLambdaFunction48e660f32023:
Value: !Ref VersionedLambdaFunction48e660f32023
VersionedLambdaFunction48e660f32023b:
Value: !Ref VersionedLambdaFunction48e660f32023b
#don't forget add the new version to output the value for cross region referencing. Note cfn import's don't work cross region so we can't lock it sadly

LambdaEdgeOriginFunctionVersion9cd5bfa:
Expand Down
2 changes: 1 addition & 1 deletion vars/cloudfront-lambda-at-edge.var.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cloudformation_stacks:
template: "{{ template }}"
template_parameters:
Environment: "{{ Environment }}"
RootDomain: "{{ RootDomain }}"
SiteDomain: "{{ SiteDomain }}"
tags:
Environment: "{{ Environment }}"
Service: "CKAN"
Expand Down

0 comments on commit 9758641

Please sign in to comment.