Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check #1

Draft
wants to merge 56 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
7729842
renamed rules.json
Aug 12, 2020
e0a723a
Adding rules file
naeemhaq Aug 12, 2020
da973a1
typo of comma
Aug 12, 2020
22aa8de
testing regex1
Aug 12, 2020
4a005d5
regextest2
Aug 12, 2020
1c847b2
renamed the file and regextext
Aug 12, 2020
6644e24
regextest3
Aug 12, 2020
dde6e54
regextest4
Aug 12, 2020
a00c02d
regextest4
Aug 12, 2020
c8e53d8
regextest5
Aug 12, 2020
24a31f9
regextest6
Aug 12, 2020
c4af320
regextest7
Aug 12, 2020
b9ecbd0
regextest7
Aug 12, 2020
dad8997
regextest8
Aug 12, 2020
4e56139
regextest9
Aug 12, 2020
ad93714
added packing script
Aug 17, 2020
746f8ea
adding cloudformation template
Aug 17, 2020
02ba923
updating rules
Aug 18, 2020
efcbf2e
Added Redirect switch to couple of rules
Aug 18, 2020
5406b28
testrule1
Aug 18, 2020
063f5ff
simplified rules
Aug 19, 2020
bccf06b
Adding host url to regex matching rule
Aug 19, 2020
c1c18e0
adding Redirect switch-flag
Aug 19, 2020
03ea13e
Added NC switch
Aug 19, 2020
8789297
testing regex
Aug 19, 2020
2e2b435
troubleshooting trailing slash in url
Aug 19, 2020
c5ea341
added end of line switch
Aug 19, 2020
ada301c
added ignore case flag
Aug 19, 2020
82ac066
back to the old rules
Aug 19, 2020
78cfd30
path rewrite test
Aug 19, 2020
a8a9ee4
removing digits from paths
Aug 19, 2020
58e336f
added end of line
Aug 19, 2020
db51a85
added end of line
Aug 19, 2020
7360652
test rules1
Aug 19, 2020
72c1fcd
testing limitted set of rules
Aug 19, 2020
30cab85
single rule test
Aug 19, 2020
565c844
testing single rule
Aug 19, 2020
d91440d
removed end of line $
Aug 19, 2020
5e0ec0e
short rules test
Aug 20, 2020
bc9ccf3
reverting back to a previous commit
Aug 20, 2020
00520f9
removed target domainName
Aug 20, 2020
26c17ab
added Hostmatch rule
Aug 20, 2020
03ea5f0
removing slashes from host address for hostmatch
Aug 20, 2020
1314b42
(.+) capture group test
Aug 20, 2020
530acac
reduced rules
Aug 20, 2020
addff45
revert back the previous rule and added Redirect
Aug 20, 2020
d3edbd1
testing simple path
Aug 21, 2020
4b94822
test rewrite
Aug 21, 2020
fcd3df0
rewrite test
Aug 21, 2020
99b5e8e
r switch
Aug 21, 2020
b957429
removing redirect rule
naeemhaq Aug 23, 2020
9cbf9f2
Update rules_.json
naeemhaq Aug 23, 2020
2c43b3f
Update rules_.json
naeemhaq Aug 23, 2020
9d8054b
Update rules_.json
naeemhaq Aug 23, 2020
441f0e4
Update rules_.json
naeemhaq Aug 23, 2020
eabea81
Update rules_.json
naeemhaq Aug 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions cloudformation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
AWSTemplateFormatVersion: 2010-09-09
Description: This CloudFormation template for deploying edge re-write lambda function.

Parameters:
S3SourceBucket:
Type: String
Description: S3 bucket containing lambda code zip file
Default: 'aws-landing-zone-s3-shared-sse-469685743753-ca-central-1'
LambdaCodeZipFile:
Type: 'String'
Description: 'Name of the zip file of the lambda code'
Default: 'edge-rewrite-master.zip'

Resources:
edgeRewriteRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: edge-rewrite-role
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
- edgelambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: edgeRewritePolicy
PolicyDocument:
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: '*'
EdgeRewriteFunction:
Type: AWS::Lambda::Function
DependsOn: edgeRewriteRole
Properties:
Code:
S3Bucket: !Ref S3SourceBucket
S3Key: !Ref LambdaCodeZipFile
FunctionName : 'Edge-Rewrite'
Handler: 'handler.handler'
Role:
Fn::GetAtt:
- 'edgeRewriteRole'
- 'Arn'
Runtime: nodejs12.x
Timeout: 900

42 changes: 42 additions & 0 deletions edge-rewrite.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@echo off

rem go to directory where cmd script is
cd %~dp0

rem check for 7z.exe
rem todo : allow for an environment variable that defines location of 7zip
if not exist "c:\program files\7-zip\7z.exe" goto need7zip

rem cut up date and time to use for backup filename
set CUR_YYYY=%date:~0,4%
set CUR_MM=%date:~5,2%
set CUR_DD=%date:~8,2%
set CUR_HH=%time:~0,2%
if %CUR_HH% lss 10 (set CUR_HH=0%time:~1,1%)

set CUR_MI=%time:~3,2%
set CUR_SS=%time:~6,2%
set CUR_MS=%time:~9,2%

rem rename zip file for safe keeping
rename Edge-Rewrite.zip Edge-Rewrite_%CUR_YYYY%%CUR_MM%%CUR_DD%_%CUR_HH%%CUR_MI%%CUR_SS%-bak.zip
cd Edge-Rewrite
"c:\program files\7-zip\7z.exe" a -r -x!*.bak ..\Edge-Rewrite.zip *
if errorlevel 1 goto zipError

goto end

:need7zip
echo 7zip is either not installed or not found at c:\program files\7-zip
rem pause
goto end

:zipError
echo.
echo ERROR zipping config file
echo See messages above
rem pause
goto end

:end
pause
7 changes: 0 additions & 7 deletions rules.sample.json

This file was deleted.

35 changes: 35 additions & 0 deletions rules_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
"^/hosted/rest/services/EGS_SGU/EGS_Flood_Product_Active_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Flood_Inondation/EGS_Flood_Product_Active_en/$1 [R]",
"^/hosted/rest/services/EGS_SGU/EGS_Flood_Product_Active_fr/(.+) /egs_sgu/rest/services/Flood_Inondation/EGS_Flood_Product_Active_fr/$1",
"^/hosted/services/EGS_SGU/EGS_Flood_Product_Active_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/services/Flood_Inondation/EGS_Flood_Product_Active_en/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_Flood_Product_Active_fr/(.+) https://maps-stage.services.geo.ca/egs_sgu/services/Flood_Inondation/EGS_Flood_Product_Active_fr/$1 [R] ",
"^/hosted/rest/services/EGS_SGU/EGS_Flood_Product_Current_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Flood_Inondation/EGS_Flood_Product_Current_en/$1 [R]",
"^/hosted/rest/services/EGS_SGU/EGS_Flood_Product_Current_fr/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Flood_Inondation/EGS_Flood_Product_Current_fr/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_Flood_Product_Current_en/(.+) https://maps-stage.services.geo.ca/egs-sgu/services/Flood_Inondation/EGS_Flood_Product_Current_en/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_Flood_Product_Current_fr/(.+) https://maps-stage.services.geo.ca/egs_sgu/services/Flood_Inondation/EGS_Flood_Product_Current_fr/$1 [R]",
"^/hosted/rest/services/EGS_SGU/EGS_Flood_Product_Archive_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Flood_Inondation/EGS_Flood_Product_Archive_en/$1 [R]",
"^/hosted/rest/services/EGS_SGU/EGS_Flood_Product_Archive_fr/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Flood_Inondation/EGS_Flood_Product_Archive_fr/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_Flood_Product_Archive_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/services/Flood_Inondation/EGS_Flood_Product_Archive_en/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_Flood_Product_Archive_fr/(.+) https://maps-stage.services.geo.ca/egs_sgu/services/Flood_Inondation/EGS_Flood_Product_Archive_fr/$1 [R]",
"^/hosted/rest/services/EGS_SGU/EGS_RiverIce_Product_Active_FP_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Ice_Glace/EGS_RiverIce_Product_Active_FP_en/$1 [R]",
"^/hosted/rest/services/EGS_SGU/EGS_RiverIce_Product_Active_FP_fr/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Ice_Glace/EGS_RiverIce_Product_Active_FP_fr/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_RiverIce_Product_Active_FP_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/services/Ice_Glace/EGS_RiverIce_Product_Active_FP_en/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_RiverIce_Product_Active_FP_fr/(.+) https://maps-stage.services.geo.ca/egs_sgu/services/Ice_Glace/EGS_RiverIce_Product_Active_FP_fr/$1 [R]",
"^/hosted/rest/services/Hosted/EGS_RiverIce_Product_Active/(.+) https://maps-stage.services.geo.ca/hosted/rest/services/Hosted/EGS_RiverIce_Product_Active/$1 [R]",
"^/hosted/rest/services/EGS_SGU/EGS_RiverIce_Product_Current_FP_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Ice_Glace/EGS_RiverIce_Product_Current_FP_en/$1 [R]",
"^/hosted/rest/services/EGS_SGU/EGS_RiverIce_Product_Current_FP_fr/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Ice_Glace/EGS_RiverIce_Product_Current_FP_fr/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_RiverIce_Product_Current_FP_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/services/Ice_Glace/EGS_RiverIce_Product_Current_FP_en/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_RiverIce_Product_Current_FP_fr/(.+) https://maps-stage.services.geo.ca/egs_sgu/services/Ice_Glace/EGS_RiverIce_Product_Current_FP_fr/$1 [R]",
"^/hosted/rest/services/Hosted/EGS_RiverIce_Product_Current/(.+) https://maps-stage.services.geo.ca/hosted/rest/services/Hosted/EGS_RiverIce_Product_Current/$1 [R]",
"^/hosted/rest/services/EGS_SGU/EGS_RiverIce_Product_Archive_FP_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Ice_Glace/EGS_RiverIce_Product_Archive_FP_en/$1 [R]",
"^/hosted/rest/services/EGS_SGU/EGS_RiverIce_Product_Archive_FP_fr/(.+) https://maps-stage.services.geo.ca/egs_sgu/rest/services/Ice_Glace/EGS_RiverIce_Product_Archive_FP_fr/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_RiverIce_Product_Archive_FP_en/(.+) https://maps-stage.services.geo.ca/egs_sgu/services/Ice_Glace/EGS_RiverIce_Product_Archive_FP_en/$1 [R]",
"^/hosted/services/EGS_SGU/EGS_RiverIce_Product_Archive_FP_fr/(.+) /egs_sgu/services/Ice_Glace/EGS_RiverIce_Product_Archive_FP_fr/$1",
"^/hosted/rest/services/Hosted/EGS_RiverIce_Product_Archive/(.+) /hosted/rest/services/Hosted/EGS_RiverIce_Product_Archive/$1",
"^/hosted/rest/services/EGS_SGU/EGS_AcquisitionPlan_Collection_Active_en/(.+) /egs_sgu/rest/services/Acquisition_Plan/EGS_AcquisitionPlan_Collection_Active_en/$1",
"^/hosted/rest/services/EGS_SGU/EGS_AcquisitionPlan_Collection_Active_fr/(.+) /egs_sgu/rest/services/Acquisition_Plan/EGS_AcquisitionPlan_Collection_Active_fr/$1",
"^/hosted/services/EGS_SGU/EGS_AcquisitionPlan_Collection_Active_en/(.+) /egs_sgu/services/Acquisition_Plan/EGS_AcquisitionPlan_Collection_Active_en/$1",
"^/hosted/services/EGS_SGU/EGS_AcquisitionPlan_Collection_Active_fr/(.+) /egs_sgu/services/Acquisition_Plan/EGS_AcquisitionPlan_Collection_Active_fr/$1",
"^/alb /portal/home [H=maps-stage.egs-redir.services.geo.ca]",
"^/oldpath /newpath"
]
88 changes: 88 additions & 0 deletions serverlesscftemplate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
AWSTemplateFormatVersion: 2010-09-09
Description: The AWS CloudFormation template for this Serverless application
Resources:
ServerlessDeploymentBucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
ServerlessDeploymentBucketPolicy:
Type: 'AWS::S3::BucketPolicy'
Properties:
Bucket: !Ref ServerlessDeploymentBucket
PolicyDocument:
Statement:
- Action: 's3:*'
Effect: Deny
Principal: '*'
Resource:
- !Join
- ''
- - 'arn:'
- !Ref 'AWS::Partition'
- ':s3:::'
- !Ref ServerlessDeploymentBucket
- /*
Condition:
Bool:
'aws:SecureTransport': false
RedirectsLogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
LogGroupName: /aws/lambda/edge-rewrite-prod-redirects
RedirectsLambdaFunction:
Type: 'AWS::Lambda::Function'
Properties:
Code:
S3Bucket: !Ref ServerlessDeploymentBucket
S3Key: >-
serverless/edge-rewrite/prod/1597686890418-2020-08-17T17:54:50.418Z/redirects.zip
FunctionName: edge-rewrite-prod-redirects
Handler: _optimize/edge-rewrite-prod-redirects/handler.handler
MemorySize: 128
Role: !GetAtt
- edgeRewriteRole0
- Arn
Runtime: nodejs10.x
Timeout: 1
DependsOn:
- RedirectsLogGroup
- edgeRewriteRole0
RedirectsLambdaVersionZR48yggZG3QaSsHAr4ehhOlyd5PmZT30l87x6tpPc8:
Type: 'AWS::Lambda::Version'
DeletionPolicy: Retain
Properties:
FunctionName: !Ref RedirectsLambdaFunction
CodeSha256: hMUDG4BG8RoDD6P5uh3ItjO6xfUgg/PAZ7f0u5WxASo=
edgeRewriteRole0:
Type: 'AWS::IAM::Role'
Properties:
RoleName: edgeRewriteRole-prod
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
- edgelambda.amazonaws.com
Action: 'sts:AssumeRole'
Policies:
- PolicyName: edgeRewriteRolePolicy-prod
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: 'arn:aws:logs:us-east-1::log-group:/aws/lambda/*:*:*'
Outputs:
ServerlessDeploymentBucketName:
Value: !Ref ServerlessDeploymentBucket
RedirectsLambdaFunctionQualifiedArn:
Description: Current Lambda function version
Value: !Ref RedirectsLambdaVersionZR48yggZG3QaSsHAr4ehhOlyd5PmZT30l87x6tpPc8