Skip to content

Commit 67a35af

Browse files
committed
initial commit
1 parent e440a1a commit 67a35af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+52939
-25
lines changed

.github/ISSUE_TEMPLATE.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Bug Report
2+
description: File a bug report
3+
title: "[Bug]: "
4+
labels: ["bug", "triage"]
5+
assignees:
6+
- jeromevdl
7+
body:
8+
- type: markdown
9+
attributes:
10+
value: |
11+
Thanks for taking the time to fill out this bug report!
12+
- type: textarea
13+
id: what-happened
14+
attributes:
15+
label: What happened?
16+
description: Also tell us, what did you expect to happen?
17+
placeholder: Tell us what you see!
18+
value: "A bug happened!"
19+
validations:
20+
required: true
21+
- type: textarea
22+
id: logs
23+
attributes:
24+
label: Relevant log output
25+
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
26+
render: shell
27+
- type: checkboxes
28+
id: terms
29+
attributes:
30+
label: Code of Conduct
31+
description: By submitting this issue, you agree to follow our [Code of Conduct](https://example.com)
32+
options:
33+
- label: I agree to follow this project's Code of Conduct
34+
required: true

.github/PULL_REQUEST_TEMPLATE.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Pull Request Template
2+
3+
## Description
4+
5+
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
6+
7+
Fixes # (issue)
8+
9+
## Type of change
10+
11+
Please delete options that are not relevant.
12+
13+
- [ ] Bug fix (non-breaking change which fixes an issue)
14+
- [ ] New feature (non-breaking change which adds functionality)
15+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
16+
- [ ] This change requires a documentation update
17+
18+
## How Has This Been Tested?
19+
20+
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
21+
22+
- [ ] Test A
23+
- [ ] Test B
24+
25+
**Test Configuration**:
26+
* Tools versions (node, CDK, SDK, ...)
27+
28+
## Checklist:
29+
30+
- [ ] My code follows the style guidelines of this project
31+
- [ ] I have performed a self-review of my own code
32+
- [ ] I have commented my code, particularly in hard-to-understand areas
33+
- [ ] I have made corresponding changes to the documentation
34+
- [ ] My changes generate no new warnings
35+
- [ ] I have added tests that prove my fix is effective or that my feature works
36+
- [ ] New and existing unit tests pass locally with my changes
37+
- [ ] Any dependent changes have been merged and published in downstream modules
38+
- [ ] I have checked my code and corrected any misspellings

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
!jest.config.js
2+
*.d.ts
3+
node_modules
4+
build
5+
6+
# CDK asset staging directory
7+
.cdk.staging
8+
cdk.out
9+
10+
.idea/
11+
12+
repolinter

.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out

CHANGELOG

Whitespace-only changes.

LICENSE

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
MIT No Attribution
2-
31
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4-
5-
Permission is hereby granted, free of charge, to any person obtaining a copy of
6-
this software and associated documentation files (the "Software"), to deal in
7-
the Software without restriction, including without limitation the rights to
8-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9-
the Software, and to permit persons to whom the Software is furnished to do so.
10-
11-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
13-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
15-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17-
2+
SPDX-License-Identifier: MIT-0
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
5+
software and associated documentation files (the "Software"), to deal in the Software
6+
without restriction, including without limitation the rights to use, copy, modify,
7+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
11+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
12+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
13+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
14+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
15+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

NOTICE

Whitespace-only changes.

README.md

+63-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,71 @@
1-
## My Project
1+
# Protecting a Lambda Function URL with Amazon CloudFront and Lambda@Edge
22

3-
TODO: Fill this README out!
3+
This repository is provided in support to an AWS blog post: [Protecting a Lambda Function URL with Amazon CloudFront and Lambda@Edge](https://aws.amazon.com/blogs/compute/protecting-an-aws-lambda-function-url-with-amazon-cloudfront-and-lambdaedge/)
44

5-
Be sure to:
5+
## Overview
66

7-
* Change the title in this README
8-
* Edit your repository description on GitHub
7+
### Architecture
98

10-
## Security
9+
The solution is based on the following architecture:
1110

12-
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
11+
![Architecture](assets/archi.png)
1312

14-
## License
13+
More details can be found in the blog post.
14+
15+
### Structure of the solution
16+
17+
This repository contains 3 main components, available in the src folder:
18+
- The frontend, a single page web application built with React and CloudScape.
19+
- The AWS Lambda functions code. The application is a simple CRUD around books.
20+
- The infrastructure code, provided as AWS CDK.
21+
22+
## Pre-requisites
23+
24+
To deploy this solution you need the following pre-requisites:
25+
26+
- An AWS Account.
27+
- The AWS Command Line Interface (CLI) installed and configured for use. Refer this link to install the CLI. https://aws.amazon.com/cli/
28+
29+
The user profile used to implement this reference solution should have enough privileges to create the following resources:
30+
- IAM roles and policies
31+
- Lambda function and function url
32+
- Cloudfront Distribution & Lambda@Edge function
33+
- Systems Manager parameters
34+
35+
- Node JS is installed ( pre-requisite to install AWS CDK ). Download Node JS from here: https://nodejs.org/en/download/
1536

16-
This library is licensed under the MIT-0 License. See the LICENSE file.
37+
- The AWS CDK V2 is installed. Refer this link to install AWS CDK V2: https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_install
1738

39+
- If you've never deployed a solution with CDK, the AWS account must be bootstrapped (more info here: https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html).
40+
Execute the following command to create the necessary AWS resources (S3 bucket, IAM role/s, etc...) that CDK will use to provision AWS resources for the solution.
41+
Replace ACCOUNT-NUMBER and REGION with your account and region where you wish to deploy the solution:
42+
```shell
43+
$ cdk bootstrap aws://ACCOUNT-NUMBER/REGION
44+
```
45+
46+
## Deployment
47+
1. Clone the current repository
48+
2. Execute the following commands:
49+
50+
```shell
51+
$ cd lambda-function-url-lambda-edge
52+
$ npm install
53+
$ cdk deploy --all
54+
```
55+
56+
Note: the deployment can take up to 15 minutes to finish
57+
58+
3. Once the deployment is successful, you should have several URLs in the output of CDK:
59+
![CDK output](assets/output_cdk.png)
60+
4. You can test the deployed solution by using the frontend. URL is available in the `FrontendURL` in CDK outputs.
61+
62+
## Clean-up
63+
To remove the deployed resources from your AWS account:
64+
1. You must first remove the replicas of the Lambda@Edge function. Refer to https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-delete-replicas.html
65+
2. Execute the following command:
66+
```shell
67+
$ cdk destroy --all
68+
```
69+
70+
## License
71+
See [License](LICENSE) of the project.

SECURITY.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- markdownlint-disable MD043 -->
2+
3+
## Reporting a Vulnerability
4+
5+
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security
6+
via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/) or directly via email to aws-security@amazon.com.
7+
8+
Please do **not** create a public GitHub issue.

SUPPORT.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
If you are having trouble running this sample, make sure you have a recent version of terraform and npm and read the
2+
[requirements](README.md#-requirements) carefully.
3+
4+
If you find a bug, please submit it to our issue tracker and label it as a bug.

assets/archi.png

43.9 KB
Loading

assets/output_cdk.png

998 KB
Loading

cdk.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"app": "npx ts-node --prefer-ts-exts src/infra/BookApp.ts",
3+
"watch": {
4+
"include": [
5+
"**"
6+
],
7+
"exclude": [
8+
"README.md",
9+
"cdk*.json",
10+
"**/*.d.ts",
11+
"**/*.js",
12+
"tsconfig.json",
13+
"package*.json",
14+
"yarn.lock",
15+
"node_modules",
16+
"test"
17+
]
18+
},
19+
"context": {
20+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
21+
"@aws-cdk/core:checkSecretUsage": true,
22+
"@aws-cdk/core:target-partitions": [
23+
"aws",
24+
"aws-cn"
25+
],
26+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
27+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
28+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
29+
"@aws-cdk/aws-iam:minimizePolicies": true,
30+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
31+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
32+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
33+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
34+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
35+
"@aws-cdk/core:enablePartitionLiterals": true,
36+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
37+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
38+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
39+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
40+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
41+
"@aws-cdk/aws-route53-patters:useCertificate": true,
42+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
43+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
44+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
45+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
46+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
47+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
48+
"@aws-cdk/aws-redshift:columnId": true
49+
}
50+
}

jest.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: MIT-0
4+
*/
5+
module.exports = {
6+
testEnvironment: 'node',
7+
roots: ['<rootDir>/test'],
8+
testMatch: ['**/*.test.ts'],
9+
transform: {
10+
'^.+\\.tsx?$': 'ts-jest'
11+
}
12+
};

0 commit comments

Comments
 (0)