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: aws-python-rest-api/README.md
+88-5
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: 'AWS Simple HTTP Endpoint example in Python'
3
3
description: 'This template demonstrates how to make a simple REST API with Python running on AWS Lambda and API Gateway using the traditional Serverless Framework.'
4
4
layout: Doc
5
-
framework: v1
5
+
framework: v2
6
6
platform: AWS
7
7
language: python
8
8
authorLink: 'https://github.com/serverless'
@@ -26,7 +26,7 @@ Run this command to initialize a new project in a new working directory.
26
26
27
27
## Usage
28
28
29
-
**Deploy**
29
+
### Deployment
30
30
31
31
This example is made to work with the Serverless Framework dashboard which includes advanced features like CI/CD, monitoring, metrics, etc.
32
32
@@ -37,16 +37,99 @@ $ serverless deploy
37
37
38
38
To deploy without the dashboard you will need to remove `org` and `app` fields from the `serverless.yml`, and you won’t have to run `sls login` before deploying.
39
39
40
-
**Invoke the function locally.**
40
+
After running deploy, you should see output similar to:
41
+
42
+
```bash
43
+
Serverless: Packaging service...
44
+
Serverless: Excluding development dependencies...
45
+
Serverless: Creating Stack...
46
+
Serverless: Checking Stack create progress...
47
+
........
48
+
Serverless: Stack create finished...
49
+
Serverless: Uploading CloudFormation file to S3...
50
+
Serverless: Uploading artifacts...
51
+
Serverless: Uploading service aws-python-rest-api.zip file to S3 (711.23 KB)...
52
+
Serverless: Validating template...
53
+
Serverless: Updating Stack...
54
+
Serverless: Checking Stack update progress...
55
+
.................................
56
+
Serverless: Stack update finished...
57
+
Service Information
58
+
service: aws-python-rest-api
59
+
stage: dev
60
+
region: us-east-1
61
+
stack: aws-python-rest-api-dev
62
+
resources: 12
63
+
api keys:
64
+
None
65
+
endpoints:
66
+
ANY - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/
67
+
functions:
68
+
api: aws-python-rest-api-dev-hello
69
+
layers:
70
+
None
71
+
```
72
+
73
+
_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/).
74
+
75
+
### Invocation
41
76
77
+
After successful deployment, you can call the created application via HTTP:
Which should result in response similar to the following (removed `input` content for brevity):
84
+
85
+
```json
86
+
{
87
+
"message": "Go Serverless v2.0! Your function executed successfully!",
88
+
"input": {
89
+
...
90
+
}
91
+
}
92
+
```
93
+
94
+
### Local development
95
+
96
+
You can invoke your function locally by using the following command:
97
+
98
+
```bash
43
99
serverless invoke local --function hello
44
100
```
45
101
46
-
**Invoke the function**
102
+
Which should result in response similar to the following:
103
+
104
+
```
105
+
{
106
+
"statusCode": 200,
107
+
"body": "{\n \"message\": \"Go Serverless v2.0! Your function executed successfully!\",\n \"input\": \"\"\n}"
108
+
}
109
+
```
110
+
111
+
Alternatively, it is also possible to emulate API Gateway and Lambda locally by using `serverless-offline` plugin. In order to do that, execute the following command:
It will add the `serverless-offline` plugin to `devDependencies` in `package.json` file as well as will add it to `plugins` in `serverless.yml`.
118
+
119
+
After installation, you can start local emulation with:
120
+
50
121
```
122
+
serverless offline
123
+
```
124
+
125
+
To learn more about the capabilities of `serverless-offline`, please refer to its [GitHub repository](https://github.com/dherault/serverless-offline).
126
+
127
+
### Bundling dependencies
51
128
129
+
In case you would like to include 3rd party dependencies, you will need to use a plugin called `serverless-python-requirements`. You can set it up by running the following command:
Running the above will automatically add `serverless-python-requirements` to `plugins` section in your `serverless.yml` file and add it as a `devDependency` to `package.json` file. The `package.json` file will be automatically created if it doesn't exist beforehand. Now you will be able to add your dependencies to `requirements.txt` file (`Pipfile` and `pyproject.toml` is also supported but requires additional configuration) and they will be automatically injected to Lambda package during build process. For more details about the plugin's configuration, please refer to [official documentation](https://github.com/UnitedIncome/serverless-python-requirements).
0 commit comments