Skip to content

Commit f7c2ec6

Browse files
authored
feature: improve tests, update docs (#580)
1 parent 338fa07 commit f7c2ec6

15 files changed

+286
-288
lines changed

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ community_bridge: # Replace with a single Community Bridge project-name e.g., cl
99
liberapay: # Replace with a single Liberapay username
1010
issuehunt: # Replace with a single IssueHunt username
1111
otechie: # Replace with a single Otechie username
12-
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
1312
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/dependabot.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/serverless-service.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
steps:
1717
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
18-
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
18+
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
1919
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
2020
- name: Check out repository code
2121
uses: actions/checkout@v3
@@ -56,6 +56,9 @@ jobs:
5656
- name: Unit tests
5757
run: |
5858
make unit
59+
- name: Infrastructure tests
60+
run: |
61+
make infra-tests
5962
- name: Deploy to AWS
6063
run: make deploy
6164
- name: Integration tests

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"Codecov",
55
"getuid",
66
"mkdocs",
7+
"mypy",
78
"ranisenberg",
8-
"runtimes"
9+
"runtimes",
10+
"yapf"
911
]
1012
}

Makefile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: dev lint complex coverage pre-commit yapf sort deploy destroy deps unit integration e2e pipeline-tests docs lint-docs
1+
.PHONY: dev lint complex coverage pre-commit yapf sort deploy destroy deps unit infra-tests integration e2e pipeline-tests docs lint-docs build
22

33

44

@@ -36,6 +36,15 @@ deps:
3636
unit:
3737
pytest tests/unit --cov-config=.coveragerc --cov=service --cov-report xml
3838

39+
build:
40+
make deps
41+
mkdir -p .build/lambdas ; cp -r service .build/lambdas
42+
mkdir -p .build/common_layer ; poetry export --without=dev --without-hashes --format=requirements.txt > .build/common_layer/requirements.txt
43+
44+
infra-tests:
45+
make build
46+
pytest tests/infrastructure
47+
3948
integration:
4049
pytest tests/integration --cov-config=.coveragerc --cov=service --cov-report xml
4150

@@ -51,9 +60,7 @@ pipeline-tests:
5160
pytest tests/unit tests/integration --cov-config=.coveragerc --cov=service --cov-report xml
5261

5362
deploy:
54-
make deps
55-
mkdir -p .build/lambdas ; cp -r service .build/lambdas
56-
mkdir -p .build/common_layer ; poetry export --without=dev --without-hashes --format=requirements.txt > .build/common_layer/requirements.txt
63+
make build
5764
cdk deploy --app="python3 ${PWD}/app.py" --require-approval=never
5865

5966
destroy:

cdk/setup.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name='service-cdk',
10-
version='3.0',
10+
version='3.1',
1111
description='CDK code for deploying an AWS Lambda handler that implements the best practices described at https://www.ranthebuilder.cloud',
1212
classifiers=[
1313
'Intended Audience :: Developers',
@@ -21,10 +21,5 @@
2121
package_data={'': ['*.json']},
2222
include_package_data=True,
2323
python_requires='>=3.9',
24-
install_requires=[
25-
'aws-cdk-lib>=2.0.0',
26-
'constructs>=10.0.0',
27-
'cdk-nag>2.0.0',
28-
'aws-cdk.aws-lambda-python-alpha==2.63.0-alpha.0',
29-
],
24+
install_requires=[],
3025
)

docs/cdk.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ description: AWS Lambda Cookbook CDK Project
66

77
- Follow this [getting started with CDK guide](https://docs.aws.amazon.com/cdk/v1/guide/getting_started.html){:target="_blank" rel="noopener"}
88
- Make sure your AWS account and machine can deploy an AWS Cloudformation stack and have all the tokens and configuration as described in the page above.
9-
- CDK Best practices [blog](https://github.com/ran-isenberg/aws-lambda-handler-cookbook){:target="_blank" rel="noopener"}
9+
- CDK Best practices [blog](https://www.ranthebuilder.cloud/post/aws-cdk-best-practices-from-the-trenches){:target="_blank" rel="noopener"}
10+
- Lambda layers best practices [blog](https://www.ranthebuilder.cloud/post/aws-lambda-layers-best-practice){:target="_blank" rel="noopener"}
1011

1112
## **CDK Deployment**
1213

@@ -39,16 +40,16 @@ All ASW Lambda function configurations are saved as constants at the `cdk.my_ser
3940

4041
- AWS Cloudformation stack: **cdk.my_service.service_stack.py** which is consisted of one construct
4142
- Construct: **cdk.my_service.api_construct.py** which includes:
42-
- **Lambda Layer** - deployment optimization meant to be used with multiple handlers under the same API GW, sharing code logic and dependencies. You can read more about it in Yan - Cui's [blog](https://medium.com/theburningmonk-com/lambda-layer-not-a-package-manager-but-a-deployment-optimization-85ddcae40a96){:target="_blank" rel="noopener"}
43+
- **Lambda Layer** - deployment optimization meant to be used with multiple handlers under the same API GW, sharing code logic and dependencies. You can read more about it [here.](https://www.ranthebuilder.cloud/post/aws-lambda-layers-best-practice){:target="_blank" rel="noopener"}
4344
- **Lambda Function** - The Lambda handler function itself. Handler code is taken from the service `folder`.
4445
- **Lambda Role** - The role of the Lambda function.
4546
- **API GW with Lambda Integration** - API GW with a Lambda integration POST /api/orders that triggers the Lambda function.
4647
- **AWS DynamoDB table** - stores request data. Created in its own construct: api_db_construct.py
4748

48-
### **CDK Tests**
49+
### **Infrastructure CDK & Security Tests**
4950

50-
Under E2E tests there is a folder `test_infra` for infrastructure tests.
51+
Under tests there is an `infrastructure` folder for CDK & security infrastructure tests.
5152

52-
First test 'test_cdk' uses CDK's testing framework which asserts that required resources exists so the application will not break anything upon deployment.
53+
The first test, 'test_cdk' uses CDK's testing framework which asserts that required resources exists so the application will not break anything upon deployment.
5354

54-
Second test 'test_cdk_nag' checks your cloudformation output for security best practices. For more information click [here](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/check-aws-cdk-applications-or-cloudformation-templates-for-best-practices-by-using-cdk-nag-rule-packs.html){:target="_blank" rel="noopener"}.
55+
The second test, 'test_cdk_nag' checks your cloudformation output for security best practices. For more information click [here](https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/check-aws-cdk-applications-or-cloudformation-templates-for-best-practices-by-using-cdk-nag-rule-packs.html){:target="_blank" rel="noopener"}.

docs/pipeline.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ All steps can be run locally using the makefile. See details below:
1818
- Python formatter Yapf as defined in `.style` - run `make yapf` in the IDE
1919
- Python complexity checks: radon and xenon - run `make complex` in the IDE
2020
- Unit tests. Run `make unit` to run unit tests in the IDE
21+
- Infrastructure test. Run `make infra-tests` to run the CDK & security infrastructure tests in the IDE
2122
- Code coverage by [codecov.io](https://about.codecov.io/)
2223
- Deploy CDK - not run in GitHub yet (add your own AWS secrets), can be run locally at this moment - run `make deploy` in the IDE
2324
- E2E tests - not run in GitHub yet (add your own AWS secrets), can be run locally at this moment - run `make e2e` in the IDE

0 commit comments

Comments
 (0)