Skip to content

Commit 5e7115d

Browse files
committed
add simple python example
1 parent 573ab1c commit 5e7115d

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ env.yml
1919
env.json
2020
admin.env
2121
tmp
22+
*.pyc
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Simple HTTP Endpoint Example
2+
3+
This example demonstrates how to setup a simple HTTP GET endpoint. Once you ping it, it will reply with the current time. While the internal function is name `currentTime` the HTTP endpoint is exposed as `ping`.
4+
5+
## Use Cases
6+
7+
- Wrapping an existing internal or external endpoint/service
8+
9+
## Deploy
10+
11+
In order to deploy the you endpoint simply run
12+
13+
```bash
14+
serverless deploy
15+
```
16+
17+
The expected result should be similar to:
18+
19+
```bash
20+
Serverless: Packaging service...
21+
Serverless: Uploading CloudFormation file to S3...
22+
Serverless: Uploading service .zip file to S3 (758 B)...
23+
Serverless: Updating Stack...
24+
Serverless: Checking Stack update progress...
25+
..........
26+
Serverless: Stack update finished...
27+
28+
Service Information
29+
service: aws-python-simple-http-endpoint
30+
stage: dev
31+
region: us-east-1
32+
api keys:
33+
None
34+
endpoints:
35+
GET - https://f7r5srabr3.execute-api.us-east-1.amazonaws.com/dev/ping
36+
functions:
37+
aws-python-simple-http-endpoint-dev-currentTime: arn:aws:lambda:us-east-1:377024778620:function:aws-python-simple-http-endpoint-dev-currentTime
38+
```
39+
40+
## Usage
41+
42+
You can now invoke the Lambda directly and even see the resulting log via
43+
44+
```bash
45+
serverless invoke --function currentTime --log
46+
```
47+
48+
The expected result should be similar to:
49+
50+
```bash
51+
{
52+
"body": "{\"message\": \"Hello, the current time is 15:40:19.009371\"}",
53+
"statusCode": 200
54+
}
55+
--------------------------------------------------------------------
56+
START RequestId: a26699d3-b3ee-11e6-9802-f33f952e8294 Version: $LATEST
57+
END RequestId: a26699d3-b3ee-11e6-9802-f33f952e8294
58+
REPORT RequestId: a26699d3-b3ee-11e6-9802-f33f952e8294 Duration: 0.23 ms Billed Duration: 100 ms Memory Size: 1024 MB Max Memory Used: 15 MB
59+
```
60+
61+
Finally you can send an HTTP request directly to the endpoint using a tool like curl
62+
63+
```bash
64+
curl https://XXXXXXX.execute-api.us-east-1.amazonaws.com/dev/ping
65+
```
66+
67+
The expected result should be similar to:
68+
69+
```bash
70+
{"message": "Hello, the current time is 15:38:53.668501"}%
71+
```
72+
73+
## Scaling
74+
75+
By default, AWS Lambda limits the total concurrent executions across all functions within a given region to 100. The default limit is a safety limit that protects you from costs due to potential runaway or recursive functions during initial development and testing. To increase this limit above the default, follow the steps in [To request a limit increase for concurrent executions](http://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html#increase-concurrent-executions-limit).
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import json
2+
import datetime
3+
4+
5+
def endpoint(event, context):
6+
current_time = datetime.datetime.now().time()
7+
body = {
8+
"message": "Hello, the current time is " + str(current_time)
9+
}
10+
11+
response = {
12+
"statusCode": 200,
13+
"body": json.dumps(body)
14+
}
15+
16+
return response
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
service: aws-python-simple-http-endpoint
2+
3+
frameworkVersion: ">=1.2.0 <2.0.0"
4+
5+
provider:
6+
name: aws
7+
runtime: python2.7
8+
9+
functions:
10+
currentTime:
11+
handler: handler.endpoint
12+
events:
13+
- http:
14+
path: ping
15+
method: get

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy