Skip to content

Commit ad5275d

Browse files
ran-isenbergRan Isenberg
and
Ran Isenberg
authored
docs: add article and other minor fixes as well ad deps updates (#869)
Co-authored-by: Ran Isenberg <[email protected]>
1 parent 3e6b9d5 commit ad5275d

10 files changed

+540
-456
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repos:
2626
exclude: "^(?!helpers/)"
2727
- repo: https://github.com/astral-sh/ruff-pre-commit
2828
# Ruff version.
29-
rev: v0.5.5
29+
rev: v0.6.1
3030
hooks:
3131
# Run the Ruff linter.
3232
- id: ruff

README.md

+63-51
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# AWS Lambda Handler Cookbook (Python)
32

43
[![license](https://img.shields.io/github/license/ran-isenberg/aws-lambda-handler-cookbook)](https://github.com/ran-isenberg/aws-lambda-handler-cookbook/blob/master/LICENSE)
@@ -13,36 +12,47 @@
1312

1413
This project provides a working, open source based, AWS Lambda handler skeleton Python code including DEPLOYMENT code with CDK and a pipeline.
1514

16-
This project can serve as a template for new Serverless services - CDK deployment code, pipeline and handler are covered.
15+
This project can serve as a blueprint for new Serverless services - CDK deployment code, pipeline and handler are covered.
1716

1817
**[📜Documentation](https://ran-isenberg.github.io/aws-lambda-handler-cookbook/)** | **[Blogs website](https://www.ranthebuilder.cloud)**
19-
> **Contact details | [email protected]**
18+
> **Contact details | mailto:[email protected]**
2019
2120
[![Twitter Follow](https://img.shields.io/twitter/follow/IsenbergRan?label=Follow&style=social)](https://twitter.com/IsenbergRan)
2221
[![Website](https://img.shields.io/badge/Website-www.ranthebuilder.cloud-blue)](https://www.ranthebuilder.cloud/)
2322

23+
## AWS Recommendation
24+
25+
This repository was recommended in an AWS blog post [Best practices for accelerating development with serverless blueprints](https://aws.amazon.com/blogs/infrastructure-and-automation/best-practices-for-accelerating-development-with-serverless-blueprints/)
26+
27+
![aws_article](https://github.com/ran-isenberg/aws-lambda-handler-cookbook/blob/main/docs/media/article.png?raw=true)
28+
29+
## Concepts
30+
31+
I spoke at AWS re:invent 2023 with Heitor Lessa, former Chief Architect of Powertools for AWS Lambda about the concepts I implemented in this project.
32+
33+
[![Watch the video](https://img.youtube.com/vi/52W3Qyg242Y/maxresdefault.jpg)](https://www.youtube.com/watch?v=52W3Qyg242Y)
34+
2435
## Getting Started
2536

26-
You can start with a clean service out of this template repository without using the 'Template' button on GitHub.
37+
You can start with a clean service out of this blueprint repository without using the 'Template' button on GitHub.
2738

2839
You can use Cookiecutter.
2940

3041
* Cookiecutter - install with pip/brew ``brew install cookiecutter`` or ``pip install cookiecutter``
3142

3243
Then run:
3344

34-
```
45+
```bash
3546
cookiecutter gh:ran-isenberg/cookiecutter-serverless-python
3647
```
3748

3849
Answer the questions to select repo name, service name, etc.:
3950

4051
![logo](https://github.com/ran-isenberg/cookiecutter-serverless-python/blob/main/media/howto.png?raw=true)
4152

42-
4353
**That's it, your developer environment has been set! you are ready to deploy the service:**
4454

45-
```
55+
```bash
4656
cd {new repo folder}
4757
poetry shell
4858
make deploy
@@ -54,99 +64,101 @@ You can also run 'make pr' will run all checks, synth, file formatters , unit te
5464

5565
Starting a Serverless service can be overwhelming. You need to figure out many questions and challenges that have nothing to do with your business domain:
5666

57-
- How to deploy to the cloud? What IAC framework do you choose?
58-
- How to write a SaaS-oriented CI/CD pipeline? What does it need to contain?
59-
- How do you handle observability, logging, tracing, metrics?
60-
- How do you write a Lambda function?
61-
- How do you handle testing?
62-
- What makes an AWS Lambda handler resilient, traceable, and easy to maintain? How do you write such a code?
63-
67+
* How to deploy to the cloud? What IAC framework do you choose?
68+
* How to write a SaaS-oriented CI/CD pipeline? What does it need to contain?
69+
* How do you handle observability, logging, tracing, metrics?
70+
* How do you write a Lambda function?
71+
* How do you handle testing?
72+
* What makes an AWS Lambda handler resilient, traceable, and easy to maintain? How do you write such a code?
6473

6574
## **The Solution**
6675

67-
This project aims to reduce cognitive load and answer these questions for you by providing a skeleton Python Serverless service template that implements best practices for AWS Lambda, Serverless CI/CD, and AWS CDK in one template project.
68-
69-
## Concepts
70-
71-
I spoke at AWS re:invent 2023 with Heitor Lessa, Chief Architect of Powertools for AWS Lambda about the concepts I implemented in this project.
72-
73-
[![Watch the video](https://img.youtube.com/vi/52W3Qyg242Y/maxresdefault.jpg)](https://www.youtube.com/watch?v=52W3Qyg242Y)
76+
This project aims to reduce cognitive load and answer these questions for you by providing a skeleton Python Serverless service blueprint that implements best practices for AWS Lambda, Serverless CI/CD, and AWS CDK in one blueprint project.
7477

7578
### Serverless Service - The Order service
7679

77-
- This project provides a working orders service where customers can create orders of items.
80+
* This project provides a working orders service where customers can create orders of items.
7881

79-
- The project deploys an API GW with an AWS Lambda integration under the path POST /api/orders/ and stores data in a DynamoDB table.
82+
* The project deploys an API GW with an AWS Lambda integration under the path POST /api/orders/ and stores data in a DynamoDB table.
8083

8184
![design](https://github.com/ran-isenberg/aws-lambda-handler-cookbook/blob/main/docs/media/design.png?raw=true)
8285
<br></br>
8386

8487
#### **Monitoring Design**
88+
8589
![monitoring_design](https://github.com/ran-isenberg/aws-lambda-handler-cookbook/blob/main/docs/media/monitoring_design.png?raw=true)
8690
<br></br>
87-
### **Features**
8891

89-
- Python Serverless service with a recommended file structure.
90-
- CDK infrastructure with infrastructure tests and security tests.
91-
- CI/CD pipelines based on Github actions that deploys to AWS with python linters, complexity checks and style formatters.
92-
- CI/CD pipeline deploys to dev/staging and production environments with different gates between each environment
93-
- Makefile for simple developer experience.
94-
- The AWS Lambda handler embodies Serverless best practices and has all the bells and whistles for a proper production ready handler.
95-
- AWS Lambda handler uses [AWS Lambda Powertools](https://docs.powertools.aws.dev/lambda-python/).
96-
- AWS Lambda handler 3 layer architecture: handler layer, logic layer and data access layer
97-
- Features flags and configuration based on AWS AppConfig
98-
- Idempotent API
99-
- REST API protected by WAF with four AWS managed rules in production deployment
100-
- CloudWatch dashboards - High level and low level including CloudWatch alarms
101-
- Unit, infrastructure, security, integration and end to end tests.
102-
- Automatically generated OpenAPI endpoint: /swagger with Pydantic schemas for both requests and responses
103-
- CI swagger protection - fails the PR if your swagger JSON file (stored at docs/swagger/openapi.json) is out of date
104-
- Automated protection against API breaking changes
92+
### **Features**
10593

94+
* Python Serverless service with a recommended file structure.
95+
* CDK infrastructure with infrastructure tests and security tests.
96+
* CI/CD pipelines based on Github actions that deploys to AWS with python linters, complexity checks and style formatters.
97+
* CI/CD pipeline deploys to dev/staging and production environments with different gates between each environment
98+
* Makefile for simple developer experience.
99+
* The AWS Lambda handler embodies Serverless best practices and has all the bells and whistles for a proper production ready handler.
100+
* AWS Lambda handler uses [AWS Lambda Powertools](https://docs.powertools.aws.dev/lambda-python/).
101+
* AWS Lambda handler 3 layer architecture: handler layer, logic layer and data access layer
102+
* Features flags and configuration based on AWS AppConfig
103+
* Idempotent API
104+
* REST API protected by WAF with four AWS managed rules in production deployment
105+
* CloudWatch dashboards - High level and low level including CloudWatch alarms
106+
* Unit, infrastructure, security, integration and end to end tests.
107+
* Automatically generated OpenAPI endpoint: /swagger with Pydantic schemas for both requests and responses
108+
* CI swagger protection - fails the PR if your swagger JSON file (stored at docs/swagger/openapi.json) is out of date
109+
* Automated protection against API breaking changes
106110

107111
## CDK Deployment
112+
108113
The CDK code create an API GW with a path of /api/orders which triggers the lambda on 'POST' requests.
109114

110115
The AWS Lambda handler uses a Lambda layer optimization which takes all the packages under the [packages] section in the Pipfile and downloads them in via a Docker instance.
111116

112117
This allows you to package any custom dependencies you might have, just add them to the Pipfile under the [packages] section.
113118

114119
## Serverless Best Practices
120+
115121
The AWS Lambda handler will implement multiple best practice utilities.
116122

117123
Each utility is implemented when a new blog post is published about that utility.
118124

119125
The utilities cover multiple aspect of a production-ready service, including:
120126

121-
- [Logging](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-elevate-your-handler-s-code-part-1-logging)
122-
- [Observability: Monitoring and Tracing](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-elevate-your-handler-s-code-part-2-observability)
123-
- [Observability: Business KPIs Metrics](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-elevate-your-handler-s-code-part-3-business-domain-observability)
124-
- [Environment Variables](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-environment-variables)
125-
- [Input Validation](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-elevate-your-handler-s-code-part-5-input-validation)
126-
- [Dynamic Configuration & feature flags](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-part-6-feature-flags-configuration-best-practices)
127-
- [Start Your AWS Serverless Service With Two Clicks](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-part-7-how-to-use-the-aws-lambda-cookbook-github-template-project)
128-
- [CDK Best practices](https://github.com/ran-isenberg/aws-lambda-handler-cookbook)
129-
- [Serverless Monitoring](https://www.ranthebuilder.cloud/post/how-to-effortlessly-monitor-serverless-applications-with-cloudwatch-part-one)
130-
- [API Idempotency](https://www.ranthebuilder.cloud/post/serverless-api-idempotency-with-aws-lambda-powertools-and-cdk)
131-
- [Serverless OpenAPI Documentation with AWS Powertools](https://www.ranthebuilder.cloud/post/serverless-open-api-documentation-with-aws-powertools)
127+
* [Logging](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-elevate-your-handler-s-code-part-1-logging)
128+
* [Observability: Monitoring and Tracing](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-elevate-your-handler-s-code-part-2-observability)
129+
* [Observability: Business KPIs Metrics](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-elevate-your-handler-s-code-part-3-business-domain-observability)
130+
* [Environment Variables](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-environment-variables)
131+
* [Input Validation](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-elevate-your-handler-s-code-part-5-input-validation)
132+
* [Dynamic Configuration & feature flags](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-part-6-feature-flags-configuration-best-practices)
133+
* [Start Your AWS Serverless Service With Two Clicks](https://www.ranthebuilder.cloud/post/aws-lambda-cookbook-part-7-how-to-use-the-aws-lambda-cookbook-github-blueprint-project)
134+
* [CDK Best practices](https://github.com/ran-isenberg/aws-lambda-handler-cookbook)
135+
* [Serverless Monitoring](https://www.ranthebuilder.cloud/post/how-to-effortlessly-monitor-serverless-applications-with-cloudwatch-part-one)
136+
* [API Idempotency](https://www.ranthebuilder.cloud/post/serverless-api-idempotency-with-aws-lambda-powertools-and-cdk)
137+
* [Serverless OpenAPI Documentation with AWS Powertools](https://www.ranthebuilder.cloud/post/serverless-open-api-documentation-with-aws-powertools)
132138

133139
## Getting started
140+
134141
Head over to the complete project documentation pages at GitHub pages at [https://ran-isenberg.github.io/aws-lambda-handler-cookbook](https://ran-isenberg.github.io/aws-lambda-handler-cookbook/)
135142

136143
## Code Contributions
144+
137145
Code contributions are welcomed. Read this [guide.](https://github.com/ran-isenberg/aws-lambda-handler-cookbook/blob/main/CONTRIBUTING.md)
138146

139147
## Code of Conduct
148+
140149
Read our code of conduct [here.](https://github.com/ran-isenberg/aws-lambda-handler-cookbook/blob/main/CODE_OF_CONDUCT.md)
141150

142151
## Connect
152+
143153
144154
* Blog Website [RanTheBuilder](https://www.ranthebuilder.cloud)
145155
* LinkedIn: [ranisenberg](https://www.linkedin.com/in/ranisenberg/)
146156
* Twitter: [IsenbergRan](https://twitter.com/IsenbergRan)
147157

148158
## Credits
159+
149160
* [AWS Lambda Powertools (Python)](https://github.com/aws-powertools/powertools-lambda-python)
150161

151162
## License
163+
152164
This library is licensed under the MIT License. See the [LICENSE](https://github.com/ran-isenberg/aws-lambda-handler-cookbook/blob/main/LICENSE) file.

cdk/service/service_stack.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, scope: Construct, id: str, is_production_env: bool, **kwargs)
1414
self._add_stack_tags()
1515

1616
# This construct should be deployed in a different repo and have its own pipeline so updates can be decoupled
17-
# from running the service pipeline and without redeploying the service lambdas. For the sake of this template
17+
# from running the service pipeline and without redeploying the service lambdas. For the sake of this blueprint
1818
# example, it is deployed as part of the service stack
1919
self.dynamic_configuration = ConfigurationStore(
2020
self,
@@ -47,10 +47,10 @@ def _add_security_tests(self) -> None:
4747
{'id': 'AwsSolutions-IAM4', 'reason': 'policy for cloudwatch logs.'},
4848
{'id': 'AwsSolutions-IAM5', 'reason': 'policy for cloudwatch logs.'},
4949
{'id': 'AwsSolutions-APIG2', 'reason': 'lambda does input validation'},
50-
{'id': 'AwsSolutions-APIG1', 'reason': 'not mandatory in a sample template'},
51-
{'id': 'AwsSolutions-APIG3', 'reason': 'not mandatory in a sample template'},
52-
{'id': 'AwsSolutions-APIG6', 'reason': 'not mandatory in a sample template'},
53-
{'id': 'AwsSolutions-APIG4', 'reason': 'authorization not mandatory in a sample template'},
50+
{'id': 'AwsSolutions-APIG1', 'reason': 'not mandatory in a sample blueprint'},
51+
{'id': 'AwsSolutions-APIG3', 'reason': 'not mandatory in a sample blueprint'},
52+
{'id': 'AwsSolutions-APIG6', 'reason': 'not mandatory in a sample blueprint'},
53+
{'id': 'AwsSolutions-APIG4', 'reason': 'authorization not mandatory in a sample blueprint'},
5454
{'id': 'AwsSolutions-COG4', 'reason': 'not using cognito'},
5555
{'id': 'AwsSolutions-L1', 'reason': 'False positive'},
5656
],

docs/getting_started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description: AWS Lambda Cookbook Project Getting started
1212

1313
## Getting Started
1414

15-
You can start with a clean service out of this template repository without using the 'Template' button on GitHub.
15+
You can start with a clean service out of this blueprint repository without using the 'Template' button on GitHub.
1616

1717
You can use Cookiecutter.
1818

docs/index.md

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
---
22
title: Homepage
3-
description: AWS Lambda Handler Cookbook - a Serverless Service Template
3+
description: AWS Lambda Handler Cookbook - a Serverless Service Blueprint
44
---
5-
## **AWS Lambda Handler Cookbook - A Serverless Service Template**
5+
## **AWS Lambda Handler Cookbook - A Serverless Service Blueprint**
66

77
[<img alt="alt_text" src="./media/banner.png" />](https://www.ranthebuilder.cloud/)
88

9+
## AWS Recommendation
10+
11+
This repository was recommended in an AWS blog post [Best practices for accelerating development with serverless blueprints](https://aws.amazon.com/blogs/infrastructure-and-automation/best-practices-for-accelerating-development-with-serverless-blueprints/){:target="_blank" rel="noopener"}
12+
13+
<img alt="aws article" src="./media/article.png" />
14+
15+
## Concepts
16+
17+
I spoke at AWS re:invent 2023 with Heitor Lessa, former Chief Architect of Powertools for AWS Lambda about the concepts I implemented in this project.
18+
19+
<iframe width="560" height="315" src="https://www.youtube.com/embed/52W3Qyg242Y" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
20+
921
## **The Problem**
1022

1123
Starting a Serverless service can be overwhelming. You need to figure out many questions and challenges that have nothing to do with your business domain:
@@ -17,25 +29,19 @@ Starting a Serverless service can be overwhelming. You need to figure out many q
1729

1830
## **The Solution**
1931

20-
This project aims to reduce cognitive load and answer these questions for you by providing a skeleton Python Serverless service template that implements best practices for AWS Lambda, Serverless CI/CD, and AWS CDK in one template project.
32+
This project aims to reduce cognitive load and answer these questions for you by providing a skeleton Python Serverless service blueprint that implements best practices for AWS Lambda, Serverless CI/CD, and AWS CDK in one blueprint project.
2133

2234
### Serverless Service - The Order service
2335

24-
<img alt="alt_text" src="./media/design.png" />
36+
<img alt="design" src="./media/design.png" />
2537

2638
- This project provides a working orders service where customers can create orders of items.
2739

2840
- The project deploys an API GW with an AWS Lambda integration under the path POST /api/orders/ and stores orders data in a DynamoDB table.
2941

3042
#### **Monitoring Design**
3143

32-
<img alt="alt_text" src="./media/monitoring_design.png" />
33-
34-
## Concepts
35-
36-
I spoke at AWS re:invent 2023 with Heitor Lessa, Chief Architect of Powertools for AWS Lambda about the concepts I implemented in this project.
37-
38-
<iframe width="560" height="315" src="https://www.youtube.com/embed/52W3Qyg242Y" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
44+
<img alt="monitoring" src="./media/monitoring_design.png" />
3945

4046
### **Features**
4147

@@ -55,7 +61,7 @@ I spoke at AWS re:invent 2023 with Heitor Lessa, Chief Architect of Powertools f
5561
- Automatically generated OpenAPI endpoint: /swagger with Pydantic schemas for both requests and responses
5662
- Automated protection against API breaking changes
5763

58-
The GitHub template project can be found at [https://github.com/ran-isenberg/aws-lambda-handler-cookbook](https://github.com/ran-isenberg/aws-lambda-handler-cookbook){:target="_blank" rel="noopener"}.
64+
The GitHub blueprint project can be found at [https://github.com/ran-isenberg/aws-lambda-handler-cookbook](https://github.com/ran-isenberg/aws-lambda-handler-cookbook){:target="_blank" rel="noopener"}.
5965

6066
## **Serverless Best Practices**
6167

docs/media/article.png

268 KB
Loading

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"dependencies": {
3-
"aws-cdk": "2.150.0"
3+
"aws-cdk": "2.152.0"
44
}
55
}

0 commit comments

Comments
 (0)