-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate CfUrlRewriter Lambda from JavaScript to TypeScript (#1660)
* Migrate CfUrlRewriter Lambda from JavaScript to TypeScript Signed-off-by: Tianle Huang <[email protected]>
- Loading branch information
Showing
8 changed files
with
138 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ node_modules | |
# CDK asset staging directory | ||
.cdk.staging | ||
cdk.out | ||
|
||
package-lock.json |
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,14 @@ | ||
import { CloudFrontRequest, CloudFrontRequestCallback, CloudFrontRequestEvent, Context } from 'aws-lambda'; | ||
|
||
export const handle = (request: CloudFrontRequest) => { | ||
// Incoming URLs from ci.opensearch.org will have a '/ci/123/' prefix, remove the prefix path from requests into S3. | ||
request.uri = request.uri.replace(/^\/ci\/...\//, '\/'); | ||
} | ||
|
||
export async function handler(event: CloudFrontRequestEvent, context: Context, callback: CloudFrontRequestCallback) { | ||
const request = event.Records[0].cf.request; | ||
|
||
handle(request); | ||
|
||
callback(null, request); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
{ | ||
"name": "cf-url-rewriter", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "cf-url-rewriter.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@types/aws-lambda": "^8.10.68", | ||
"@types/node": "^14.14.19", | ||
"typescript": "^4.1.3" | ||
} | ||
} | ||
|
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
20 changes: 20 additions & 0 deletions
20
deployment/test/lambdas/cf-url-rewriter/cf-url-rewriter.test.ts
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,20 @@ | ||
import { CloudFrontRequest } from 'aws-lambda'; | ||
import { handle } from "../../../lambdas/cf-url-rewriter/cf-url-rewriter"; | ||
|
||
test('Lmabda handle uri with ci string', () => { | ||
|
||
let request = { uri: '/ci/dbc/bundle-build-dashboards/1.2.0/428/linux/x64/' } as CloudFrontRequest; | ||
|
||
handle(request); | ||
|
||
expect(request.uri).toBe('/bundle-build-dashboards/1.2.0/428/linux/x64/'); | ||
}); | ||
|
||
test('Lmabda handle uri without ci string', () => { | ||
|
||
let request = { uri: '/bundle-build-dashboards/1.2.0/428/linux/x64/' } as CloudFrontRequest; | ||
|
||
handle(request); | ||
|
||
expect(request.uri).toBe('/bundle-build-dashboards/1.2.0/428/linux/x64/'); | ||
}); |