Skip to content

Commit 2409bc7

Browse files
committed
feat: Use httpApi in Flask Python examples
1 parent b15ccbb commit 2409bc7

File tree

4 files changed

+8
-22
lines changed

4 files changed

+8
-22
lines changed

aws-python-flask-api/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This template demonstrates how to develop and deploy a simple Python Flask API s
1818

1919
## Anatomy of the template
2020

21-
This template configures a single function, `api`, which is responsible for handling all incoming requests thanks to configured `http` events. To learn more about `http` event configuration options, please refer to [http event docs](https://www.serverless.com/framework/docs/providers/aws/events/apigateway/). As the events are configured in a way to accept all incoming requests, `Flask` framework is responsible for routing and handling requests internally. The implementation takes advantage of `serverless-wsgi`, which allows you to wrap WSGI applications such as Flask apps. To learn more about `serverless-wsgi`, please refer to corresponding [GitHub repository](https://github.com/logandk/serverless-wsgi). Additionally, the template relies on `serverless-python-requirements` plugin for packaging dependencies from `requirements.txt` file. For more details about `serverless-python-requirements` configuration, please refer to corresponding [GitHub repository](https://github.com/UnitedIncome/serverless-python-requirements).
21+
This template configures a single function, `api`, which is responsible for handling all incoming requests thanks to configured `httpApi` events. To learn more about `httpApi` event configuration options, please refer to [httpApi event docs](https://www.serverless.com/framework/docs/providers/aws/events/http-api/). As the events are configured in a way to accept all incoming requests, `Flask` framework is responsible for routing and handling requests internally. The implementation takes advantage of `serverless-wsgi`, which allows you to wrap WSGI applications such as Flask apps. To learn more about `serverless-wsgi`, please refer to corresponding [GitHub repository](https://github.com/logandk/serverless-wsgi). Additionally, the template relies on `serverless-python-requirements` plugin for packaging dependencies from `requirements.txt` file. For more details about `serverless-python-requirements` configuration, please refer to corresponding [GitHub repository](https://github.com/UnitedIncome/serverless-python-requirements).
2222

2323
## Usage
2424

@@ -68,14 +68,12 @@ Deploying aws-python-flask-api-project to stage dev (us-east-1)
6868

6969
✔ Service deployed to stack aws-python-flask-api-project-dev (182s)
7070

71-
endpoints:
72-
ANY - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/
73-
ANY - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/{proxy+}
71+
endpoint: ANY - https://xxxxxxxx.execute-api.us-east-1.amazonaws.com
7472
functions:
7573
api: aws-python-flask-api-project-dev-api (1.5 MB)
7674
```
7775

78-
_Note_: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to [http event docs](https://www.serverless.com/framework/docs/providers/aws/events/apigateway/).
76+
_Note_: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to [httpApi event docs](https://www.serverless.com/framework/docs/providers/aws/events/http-api/).
7977

8078
### Invocation
8179

aws-python-flask-api/serverless.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ functions:
1414
api:
1515
handler: wsgi_handler.handler
1616
events:
17-
- http:
18-
path: /
19-
method: ANY
20-
- http:
21-
path: /{proxy+}
22-
method: ANY
17+
- httpApi: '*'
2318

2419
plugins:
2520
- serverless-wsgi

aws-python-flask-dynamodb-api/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This template demonstrates how to develop and deploy a simple Python Flask API s
1818

1919
## Anatomy of the template
2020

21-
This template configures a single function, `api`, which is responsible for handling all incoming requests thanks to configured `http` events. To learn more about `http` event configuration options, please refer to [http event docs](https://www.serverless.com/framework/docs/providers/aws/events/apigateway/). As the events are configured in a way to accept all incoming requests, `Flask` framework is responsible for routing and handling requests internally. The implementation takes advantage of `serverless-wsgi`, which allows you to wrap WSGI applications such as Flask apps. To learn more about `serverless-wsgi`, please refer to corresponding [GitHub repository](https://github.com/logandk/serverless-wsgi). The template also relies on `serverless-python-requirements` plugin for packaging dependencies from `requirements.txt` file. For more details about `serverless-python-requirements` configuration, please refer to corresponding [GitHub repository](https://github.com/UnitedIncome/serverless-python-requirements).
21+
This template configures a single function, `api`, which is responsible for handling all incoming requests thanks to configured `httpApi` events. To learn more about `httpApi` event configuration options, please refer to [httpApi event docs](https://www.serverless.com/framework/docs/providers/aws/events/http-api/). As the events are configured in a way to accept all incoming requests, `Flask` framework is responsible for routing and handling requests internally. The implementation takes advantage of `serverless-wsgi`, which allows you to wrap WSGI applications such as Flask apps. To learn more about `serverless-wsgi`, please refer to corresponding [GitHub repository](https://github.com/logandk/serverless-wsgi). The template also relies on `serverless-python-requirements` plugin for packaging dependencies from `requirements.txt` file. For more details about `serverless-python-requirements` configuration, please refer to corresponding [GitHub repository](https://github.com/UnitedIncome/serverless-python-requirements).
2222

2323
Additionally, the template also handles provisioning of a DynamoDB database that is used for storing data about users. The Flask application exposes two endpoints, `POST /users` and `GET /user/{userId}`, which allow to create and retrieve users.
2424

@@ -64,14 +64,12 @@ Deploying aws-python-flask-dynamodb-api-project to stage dev (us-east-1)
6464

6565
✔ Service deployed to stack aws-python-flask-dynamodb-api-project-dev (182s)
6666

67-
endpoints:
68-
ANY - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/
69-
ANY - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/{proxy+}
67+
endpoint: ANY - https://xxxxxxxx.execute-api.us-east-1.amazonaws.com
7068
functions:
7169
api: aws-python-flask-dynamodb-api-project-dev-api (1.5 MB)
7270
```
7371

74-
_Note_: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to [http event docs](https://www.serverless.com/framework/docs/providers/aws/events/apigateway/).
72+
_Note_: In current form, after deployment, your API is public and can be invoked by anyone. For production deployments, you might want to configure an authorizer. For details on how to do that, refer to [httpApi event docs](https://www.serverless.com/framework/docs/providers/aws/events/http-api/).
7573

7674
### Invocation
7775

aws-python-flask-dynamodb-api/serverless.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ functions:
3131
api:
3232
handler: wsgi_handler.handler
3333
events:
34-
- http:
35-
path: /
36-
method: ANY
37-
- http:
38-
path: /{proxy+}
39-
method: ANY
34+
- httpApi: '*'
4035

4136
plugins:
4237
- serverless-wsgi

0 commit comments

Comments
 (0)