Skip to content

Commit

Permalink
[FDP-1901] Move cache policy to vpc level and use same cache policy f…
Browse files Browse the repository at this point in the history
…or each stack (#106)
  • Loading branch information
dylanmmatthews authored Aug 2, 2022
1 parent 1335f75 commit 2746e35
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 54 deletions.
50 changes: 50 additions & 0 deletions cloudformation/vpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,44 @@ Mappings:
'948629139753': '172.135'

Resources:
ApiCachePolicy:
Type: AWS::CloudFront::CachePolicy
Properties:
CachePolicyConfig:
Comment: Policy for long lived caching with Givesource settings, contents, and files
DefaultTTL: 86400
MaxTTL: 31536000
MinTTL: 1
Name: Givesource-CachePolicy
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: none
EnableAcceptEncodingGzip: true
HeadersConfig:
HeaderBehavior: whitelist
Headers: [ "Authorization" ]
QueryStringsConfig:
QueryStringBehavior: all

NoCachePolicy:
Type: AWS::CloudFront::CachePolicy
Properties:
CachePolicyConfig:
Comment: Policy for no caching with authorized headers for the admin area
DefaultTTL: 0
MaxTTL: 30
MinTTL: 0
Name: Givesource-NoCachePolicy
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: none
EnableAcceptEncodingGzip: true
HeadersConfig:
HeaderBehavior: whitelist
Headers: [ "Authorization" ]
QueryStringsConfig:
QueryStringBehavior: all

RecaptchaParameterStore:
Type: AWS::SSM::Parameter
Properties:
Expand Down Expand Up @@ -446,3 +484,15 @@ Outputs:
Export:
Name: global-recaptcha-key

globalCachePolicy:
Description: Cache policy for Givesource
Value: !GetAtt ApiCachePolicy.Id
Export:
Name: global-cache-policy

globalNoCachePolicy:
Description: No cache policy for Givesource
Value: !GetAtt NoCachePolicy.Id
Export:
Name: global-no-cache-policy

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "givesource",
"version": "2.2.1",
"version": "2.2.5",
"description": "Pay-as-you-go highly scalable software application that helps community foundations set up and manage a platform where they can raise funds for non-profits through event pages.",
"license": "Apache-2.0",
"repository": {
Expand Down
48 changes: 4 additions & 44 deletions packages/cloudformation/templates/givesource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,46 +138,6 @@ Resources:
Name: !Sub |-
${AWS::StackName}
ApiCachePolicy:
Type: AWS::CloudFront::CachePolicy
Properties:
CachePolicyConfig:
Comment: Policy for long lived caching with Givesource settings, contents, and files
DefaultTTL: 86400
MaxTTL: 31536000
MinTTL: 1
Name: !Sub ${AWS::StackName}-Givesource-CachePolicy-${AWS::Region}
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: none
EnableAcceptEncodingGzip: true
HeadersConfig:
HeaderBehavior: whitelist
Headers: ["Authorization"]
QueryStringsConfig:
QueryStringBehavior: all
DependsOn: RestApi

NoCachePolicy:
Type: AWS::CloudFront::CachePolicy
Properties:
CachePolicyConfig:
Comment: Policy for no caching with authorized headers for the admin area
DefaultTTL: 0
MaxTTL: 30
MinTTL: 0
Name: !Sub ${AWS::StackName}-Givesource-NoCachePolicy-${AWS::Region}
ParametersInCacheKeyAndForwardedToOrigin:
CookiesConfig:
CookieBehavior: none
EnableAcceptEncodingGzip: true
HeadersConfig:
HeaderBehavior: whitelist
Headers: ["Authorization"]
QueryStringsConfig:
QueryStringBehavior: all
DependsOn: RestApi

ApiDistribution:
Type: AWS::CloudFront::Distribution
Properties:
Expand All @@ -194,24 +154,24 @@ Resources:
DefaultRootObject: index.html
DefaultCacheBehavior:
AllowedMethods: ["GET", "HEAD", "OPTIONS", "PUT", "PATCH", "POST", "DELETE"]
CachePolicyId: !GetAtt NoCachePolicy.Id
CachePolicyId: !ImportValue global-no-cache-policy
TargetOriginId: !Ref RestApi
ViewerProtocolPolicy: redirect-to-https
PriceClass: PriceClass_200
CacheBehaviors:
- PathPattern: "/settings"
AllowedMethods: ["GET", "HEAD", "OPTIONS", "PUT", "PATCH", "POST", "DELETE"]
CachePolicyId: !GetAtt ApiCachePolicy.Id
CachePolicyId: !ImportValue global-cache-policy
TargetOriginId: !Ref RestApi
ViewerProtocolPolicy: redirect-to-https
- PathPattern: "/contents"
AllowedMethods: ["GET", "HEAD", "OPTIONS", "PUT", "PATCH", "POST", "DELETE"]
CachePolicyId: !GetAtt ApiCachePolicy.Id
CachePolicyId: !ImportValue global-cache-policy
TargetOriginId: !Ref RestApi
ViewerProtocolPolicy: redirect-to-https
- PathPattern: "/files"
AllowedMethods: ["GET", "HEAD", "OPTIONS", "PUT", "PATCH", "POST", "DELETE"]
CachePolicyId: !GetAtt ApiCachePolicy.Id
CachePolicyId: !ImportValue global-cache-policy
TargetOriginId: !Ref RestApi
ViewerProtocolPolicy: redirect-to-https

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
if (vue.cognitoUser) {
delete vue.userAttributes['email_verified'];
delete vue.userAttributes['email']
vue.cognitoUser.completeNewPasswordChallenge(vue.formData.password, vue.userAttributes, {
onSuccess: function () {
vue.$request.patch('users/' + vue.cognitoUser.username, {isVerified: true}).then(function () {
Expand Down
20 changes: 11 additions & 9 deletions packages/lambda/src/custom/createLambdaEdgeFunction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,17 @@ exports.handle = (event, context, callback) => {
});
}

promise.then(() => {
return lambda.publishVersion(region, functionName);
}).then(data => {
response.send(event, context, response.SUCCESS, {LambdaFunctionARN: data.FunctionArn}, data.FunctionArn);
}).catch(err => {
logger.log(err);
response.send(event, context, response.FAILED);
});

// this is necessary because of nodejs14 update... sorry to whoever sees this in the future
setTimeout(() => {
promise.then(() => {
return lambda.publishVersion(region, functionName);
}).then(data => {
response.send(event, context, response.SUCCESS, {LambdaFunctionARN: data.FunctionArn}, data.FunctionArn);
}).catch(err => {
logger.log(err);
response.send(event, context, response.FAILED);
});
}, 5000)
} else {
response.send(event, context, response.SUCCESS);
}
Expand Down
1 change: 1 addition & 0 deletions packages/lambda/src/database/bootstrapDatabase/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ exports.handle = function (event, context, callback) {

if (event.RequestType === 'Delete') {
response.send(event, context, response.SUCCESS);
callback()
return;
}

Expand Down

0 comments on commit 2746e35

Please sign in to comment.