diff --git a/cloudfront.yml b/cloudfront.yml index 232c228a..5ed0b87e 100644 --- a/cloudfront.yml +++ b/cloudfront.yml @@ -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 }}" diff --git a/templates/cloudfront-lambdaAtEdge.cfn.yml b/templates/cloudfront-lambdaAtEdge.cfn.yml index b2e8f819..f9d5ab02 100644 --- a/templates/cloudfront-lambdaAtEdge.cfn.yml +++ b/templates/cloudfront-lambdaAtEdge.cfn.yml @@ -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 @@ -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 @@ -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" }] @@ -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' @@ -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: diff --git a/vars/cloudfront-lambda-at-edge.var.yml b/vars/cloudfront-lambda-at-edge.var.yml index a761bb95..f79ff544 100644 --- a/vars/cloudfront-lambda-at-edge.var.yml +++ b/vars/cloudfront-lambda-at-edge.var.yml @@ -9,7 +9,7 @@ cloudformation_stacks: template: "{{ template }}" template_parameters: Environment: "{{ Environment }}" - RootDomain: "{{ RootDomain }}" + SiteDomain: "{{ SiteDomain }}" tags: Environment: "{{ Environment }}" Service: "CKAN"