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: README.md
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,25 @@
1
1
# AWS FastAPI Lambda
2
-
Create an API using AWS API Gateway, Lambda and FastAPI + Mangum (based on [this walkthrough](https://towardsdatascience.com/fastapi-aws-robust-api-part-1-f67ae47390f9)):
2
+
Creates an API using an AWS API Gateway and Lambda function, based on [this walkthrough](https://towardsdatascience.com/fastapi-aws-robust-api-part-1-f67ae47390f9). The setup uses:
3
+
4
+
***API:**[FastAPI](https://fastapi.tiangolo.com/)`+`[Mangum](https://mangum.io/), served by [uvicorn](https://www.uvicorn.org/)
Requests are sent to the API Gateway, which has one `/{proxy+}` resource. This resource handles all requests using a [proxy integration with the Lambda function](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html). Mangum acts as a wrapper, which allows FastAPI to handle the requests and create responses the API gateway can serve. All logs are sent to CloudWatch log groups.
3
8
4
9
```js
5
-
┌─── AWS region ────────────────────────────┐
6
-
│ ┌─── VPC ──────────────┐ │
7
-
│ │ │ │
8
-
Request ───► API Gateway ───► Lambda (FastAPI) │ │
9
-
│ │ │ │
10
-
│ │ └──────────│───────────┘ │
11
-
│ ┌───────│───────────────────│───────────┐ │
12
-
│ │ ▼ CloudWatch ▼ │ │
13
-
│ └───────────────────────────────────────┘ │
14
-
└───────────────────────────────────────────┘
10
+
┌─── AWS region ─────────────────────────────┐
11
+
│ ┌─── VPC: three AZs ────┐ │
12
+
│ │ │ │
13
+
Request ───► API Gateway ───► Lambda (FastAPI) │ │
14
+
│ │ │ │
15
+
│ │ └───────────│───────────┘ │
16
+
│ ┌───────│────────────────────│───────────┐ │
17
+
│ │ ▼ CloudWatch ▼ │ │
18
+
│ └────────────────────────────────────────┘ │
19
+
└────────────────────────────────────────────┘
15
20
```
16
21
17
-
* Lambda is deployed in a VPC, so the function has access to private resources.
18
-
* No Internet Gateway, so Lambda uses VPC endpoints for access to CloudWatch.
22
+
If performance becomes an issue, a CloudFront distribution could be added for API responses that are cacheable.
19
23
20
24
# Dev
21
25
```sh
@@ -32,7 +36,7 @@ View the [API endpoints](http://localhost:8000/docs).
32
36
cd api
33
37
make zip
34
38
35
-
# Create the API gateway and Lambda function
39
+
# Create the AWS infrastructure
36
40
cd ../infra/env/dev
37
41
terragrunt run-all plan # to see all the goodness that will get created
38
42
terragrunt run-all apply # create all the goodness
0 commit comments