You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/event_handler/api_gateway.md
+35-2Lines changed: 35 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1125,7 +1125,41 @@ This sample project contains an Users function with two distinct set of routes,
1125
1125
PYTHONPATH="users:${PYTHONPATH}"
1126
1126
```
1127
1127
1128
-
#### Trade-offs
1128
+
### Considerations
1129
+
1130
+
This utility is optimized for fast startup, minimal feature set, and to quickly on-board customers familiar with frameworks like Flask — it's not meant to be a fully fledged framework.
1131
+
1132
+
Event Handler naturally leads to a single Lambda function handling multiple routes for a given service, which can be eventually broken into multiple functions.
1133
+
1134
+
Both single (monolithic) and multiple functions (micro) offer different set of trade-offs worth knowing.
1135
+
1136
+
!!! tip "Start with a monolithic function and eventually break into multiple functions, if necessary."
1137
+
1138
+
#### Monolithic function
1139
+
1140
+

1141
+
1142
+
A monolithic function means that your final code artifact will be deployed to a single function. This is generally the best approach to start.
1143
+
1144
+
**Benefits**
1145
+
1146
+
***Code reuse**. It's easier to reason about your project, modularize it and reuse code as it grows. Eventually, it can be turned into a standalone library.
1147
+
***No custom tooling**. Monolithic functions are treated just like normal Python packages; no upfront investment in tooling.
1148
+
***Faster deployment and debugging**. Whether you use all-at-once, linear, or canary deployments, a monolithic function is a single deployable unit. IDEs like PyCharm and VSCode have tooling to quickly profile, visualize, and step through debug any Python package.
1149
+
1150
+
**Downsides**
1151
+
1152
+
***Cold starts**. Frequent deployments and/or high load can diminish the benefit of monolithic functions depending on your latency requirements, due to [Lambda scaling model](https://docs.aws.amazon.com/lambda/latest/dg/invocation-scaling.html). Always load test to pragmatically balance between your customer experience and development cognitive load.
1153
+
***Granular security permissions**. The micro function approach enables you to use fine-grained permissions, separate external dependencies & code signing at the function level. Regardless, least privilege can be applied to either approaches.
1154
+
***Higher risk per deployment**. A bad deployment can cause the entire service to stop working while a micro function will limit its blast radius. You can minimize risks by ensuring modules are tested in isolation, use multiple environments in your CI/CD pipeline, and optionally use linear/canary deployments to trade lead time for safety.
1155
+
1156
+
#### Micro function
1157
+
1158
+

1159
+
1160
+
1161
+
!!! TODO "rewrite this section"
1162
+
1129
1163
1130
1164
!!! tip "TL;DR. Balance your latency requirements, cognitive overload, least privilege, and operational overhead to decide between one, few, or many single purpose functions."
1131
1165
@@ -1139,7 +1173,6 @@ This can also quickly lead to discussions whether it facilitates a monolithic vs
1139
1173
1140
1174
**Package size**. Consider Lambda Layers for third-party dependencies and service-level shared code. Treat third-party dependencies as dev dependencies, and Lambda Layers as a mechanism to speed up build and deployments.
1141
1175
1142
-
**Cold start**. High load can diminish the benefit of monolithic functions depending on your latency requirements. Always load test to pragmatically balance between your customer experience and development cognitive load.
0 commit comments