|
| 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). |
0 commit comments