Skip to content

Commit 7c5dd89

Browse files
ran-isenbergRan Isenberg
andauthored
docs: add cicd multi stages docs (#754)
* docs: add cicd multi stages docs * add time check --------- Co-authored-by: Ran Isenberg <ran.isenberg@ranthebuilder.cloud>
1 parent 9fe00e6 commit 7c5dd89

File tree

14 files changed

+66
-20
lines changed

14 files changed

+66
-20
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ integration:
5656
e2e:
5757
poetry run pytest tests/e2e --cov-config=.coveragerc --cov=service --cov-report xml
5858

59-
pr: deps pre-commit complex lint unit deploy integration e2e
59+
pr: deps pre-commit complex lint lint-docs unit deploy coverage-tests e2e
6060

6161
coverage-tests:
6262
poetry run pytest tests/unit tests/integration --cov-config=.coveragerc --cov=service --cov-report xml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ This project aims to reduce cognitive load and answer these questions for you by
5454
- Python Serverless service with a recommended file structure.
5555
- CDK infrastructure with infrastructure tests and security tests.
5656
- CI/CD pipelines based on Github actions that deploys to AWS with python linters, complexity checks and style formatters.
57+
- CI/CD pipeline deploys to dev/staging and production environment with different gates between each environment
5758
- Makefile for simple developer experience.
5859
- The AWS Lambda handler embodies Serverless best practices and has all the bells and whistles for a proper production ready handler.
5960
- AWS Lambda handler uses [AWS Lambda Powertools](https://docs.powertools.aws.dev/lambda-python/).

docs/best_practices/environment_variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ The best practice for handling environment variables is to validate & parse them
1717
In case of misconfiguration, a validation exception is raised with all the relevant exception details.
1818

1919
## **Open source**
20+
2021
The code in this post has been moved to an open source project you can use:
2122

2223
The [AWS Lambda environment variables modeler](https://github.com/ran-isenberg/aws-lambda-env-modeler){:target="_blank" rel="noopener"}
2324

24-
2525
## **Blog Reference**
2626

2727
Read more about the importance of validating environment variables and how this utility works. Click [**HERE**](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-environment-variables){:target="_blank" rel="noopener"}

docs/best_practices/monitoring.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ description: Monitoring
88

99
## **Key Concepts**
1010

11-
Utilizing AWS CloudWatch dashboards enables centralized monitoring of API Gateway, Lambda functions, and DynamoDB, providing real-time insights into their performance and operational health. By aggregating metrics, logs, and alarms, CloudWatch facilitates swift issue diagnosis and analysis across your serverless applications. Additionally, setting up alarms ensures immediate alerts during anomalous activities, enabling proactive issue mitigation.
11+
Utilizing AWS CloudWatch dashboards enables centralized monitoring of API Gateway, Lambda functions, and DynamoDB, providing real-time insights into their performance and operational health.
12+
By aggregating metrics, logs, and alarms, CloudWatch facilitates swift issue diagnosis and analysis across your serverless applications. Additionally, setting up alarms ensures immediate alerts during anomalous activities, enabling proactive issue mitigation.
1213

1314
## **Service Architecture**
1415

@@ -54,7 +55,6 @@ As for DynamoDB tables, we have the primary database and the idempotency table f
5455

5556
Personas that use this dashboard: developers, SREs.
5657

57-
5858
### **Alarms**
5959

6060
Having visibility and information is one thing, but being proactive and knowing beforehand that a significant error is looming is another. A CloudWatch
@@ -74,7 +74,6 @@ For latency-related issues, we define the following alarm:
7474

7575
For P90, P50 metrics, follow this [explanation.](https://www.dnv.com/article/terminology-explained-p10-p50-and-p90-202611#:~:text=Proved%20(P90)%3A%20The%20lowest,equal%20or%20exceed%20P10%20estimate.){:target="_blank" rel="noopener"}
7676

77-
7877
For internal server errors rate, we define the following alarm:
7978
![5xx](../media/monitoring/alarm_5xx.png)
8079

@@ -89,7 +88,6 @@ We use the open-source [cdk-monitoring-constructs](https://github.com/cdklabs/cd
8988

9089
You can view find the monitoring CDK construct [here](https://github.com/ran-isenberg/aws-lambda-handler-cookbook/blob/main/cdk/service/monitoring.py).
9190

92-
9391
## **Further Reading**
9492

9593
If you wish to learn more about this concept and go over details on the CDK code, check out my [blog post](https://www.ranthebuilder.cloud/post/how-to-effortlessly-monitor-serverless-applications-with-cloudwatch-part-one).

docs/getting_started.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ description: AWS Lambda Cookbook Project Getting started
1010
* [poetry](https://pypi.org/project/poetry/){target="_blank"} - Make sure to run ``poetry config --local virtualenvs.in-project true`` so all dependencies are installed in the project '.venv' folder.
1111
* For Windows based machines, use the Makefile_windows version (rename to Makefile). Default Makefile is for Mac/Linux.
1212

13-
1413
## **Creating a Developer Environment**
1514

1615
1. Run ``make dev``

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This project aims to reduce cognitive load and answer these questions for you by
3232
- Python Serverless service with a recommended file structure.
3333
- CDK infrastructure with infrastructure tests and security tests.
3434
- CI/CD pipelines based on Github actions that deploys to AWS with python linters, complexity checks and style formatters.
35+
- CI/CD pipeline deploys to dev/staging and production environment with different gates between each environment
3536
- Makefile for simple developer experience.
3637
- The AWS Lambda handler embodies Serverless best practices and has all the bells and whistles for a proper production ready handler.
3738
- AWS Lambda handler uses [AWS Lambda Powertools](https://docs.powertools.aws.dev/lambda-python/){:target="_blank" rel="noopener"}.
@@ -59,6 +60,7 @@ The utilities cover multiple aspects of a production-ready service, including:
5960
- [**Dynamic configuration & features flags**](best_practices/dynamic_configuration.md)
6061
- [**Serverless Monitoring**](https://www.ranthebuilder.cloud/post/how-to-effortlessly-monitor-serverless-applications-with-cloudwatch-part-one)
6162
- [**API Idempotency**](https://www.ranthebuilder.cloud/post/serverless-api-idempotency-with-aws-lambda-powertools-and-cdk){:target="_blank" rel="noopener"}
63+
- [**Learn How to Write AWS Lambda Functions with Three Architecture Layers**](https://www.ranthebuilder.cloud/post/learn-how-to-write-aws-lambda-functions-with-architecture-layers){:target="_blank" rel="noopener"}
6264

6365
While the code examples are written in Python, the principles are valid to any supported AWS Lambda handler programming language.
6466

docs/media/cicd_main.png

55.3 KB
Loading

docs/media/cicd_pr.png

42.3 KB
Loading

docs/pipeline.md

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ title: CI/CD Pipeline
33
description: AWS Lambda Cookbook - Elevate Your Handler's Code Python pipeline
44
---
55

6-
## **CI/CD Pipeline**
6+
## **Getting Started**
77

88
The GitHub CI/CD pipeline includes the following steps.
99

1010
The pipelines uses environment secrets (under the defined environment 'dev', 'staging' and 'production') for code coverage and for the role to deploy to AWS.
1111

12-
When you clone this repository be sure to define the environments in your [repo settings](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment) and add two environment secrets:
12+
When you clone this repository be sure to define the environments in your [repo settings](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment) and create a secret per environment:
1313

14-
1. AWS_ROLE - to role to assume for your GitHub worker as defined [here](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services) .
15-
2. CODECOV_TOKEN - for [code coverage integration](https://app.codecov.io/).
14+
- AWS_ROLE - to role to assume for your GitHub worker as defined [here](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)
1615

17-
### Makefile Commands
16+
### **Makefile Commands**
1817

1918
All steps can be run locally using the makefile. See details below:
2019

@@ -34,9 +33,40 @@ All steps can be run locally using the makefile. See details below:
3433
- Code coverage tests - run `make coverage-tests` in the IDE after CDK dep
3534
- Update GitHub documentation branch
3635

37-
### Other Capabilities
36+
### **Other Capabilities**
3837

3938
- Automatic Python dependencies update with Dependabot
4039
- Easy to use makefile allows to run locally all commands in the GitHub actions
4140
- Run local docs server, prior to push in pipeline - run `make docs` in the IDE
4241
- Prepare PR, run all checks with one command - run `make pr` in the IDE
42+
43+
## **Environments & Pipelines**
44+
45+
All GitHub workflows are stored under `.github/workflows` folder.
46+
47+
The two most important ones are `pr-serverless-service` and `main-serverless-service`.
48+
49+
### **pr-serverless-service**
50+
51+
<img alt="alt_text" src="../media/cicd_pr.png" />
52+
53+
`pr-serverless-service` runs for every pull request you open. It expects you defined a GitHub environment by the name `dev` and that it includes a secret by the name of `AWS_ROLE`.
54+
55+
It includes two jobs: 'quality_standards' and 'tests' where a failure in 'quality_standards' does not trigger 'tests'. Both jobs MUST pass in order to to be able to merge.
56+
57+
'quality_standards' includes all linters, pre-commit checks and units tests and 'tests' deploys the service to AWS, runs code coverage checks, security checks and E2E tests. Stack is destroyed at the end. Stack has a 'dev' prefix as part of its name.
58+
59+
Once merged, `main-serverless-service` will run.
60+
61+
### **main-serverless-service**
62+
63+
<img alt="alt_text" src="../media/cicd_main.png" />
64+
65+
`main-serverless-service` runs for every MERGED pull request that runs on the main branch. It expects you defined a GitHub environments by the name `staging` and `production` and that both includes a secret by the name of `AWS_ROLE`.
66+
67+
It includes three jobs: 'staging', 'production' and 'publish_github_pages'.
68+
69+
'staging' does not run any of the 'quality_standards' checks, since they were already checked before the code was merged. It runs just coverage tests and E2E tests. Stack is not deleted. Stack has a 'staging' prefix as part of its name.
70+
Any failure in staging will stop the pipeline and production environment will not get updated with the new code.
71+
72+
'production' does not run any of the 'quality_standards' checks, since they were already checked before the code was merged. It does not run any test at the moment. Stack is not deleted. Stack has a 'production' prefix as part of its name.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ nav:
1414
- best_practices/tracer.md
1515
- best_practices/metrics.md
1616
- best_practices/environment_variables.md
17+
- Architecture Layers: https://www.ranthebuilder.cloud/post/learn-how-to-write-aws-lambda-functions-with-architecture-layers" target="_blank"
1718
- best_practices/input_validation.md
1819
- best_practices/dynamic_configuration.md
1920
- best_practices/monitoring.md

0 commit comments

Comments
 (0)