Skip to content

Commit 857af6d

Browse files
Update README. (#18)
- `body` field of Lambda response object must explicitly be stringified. Otherwise, Gateway throws error. - Include instructions for uploading the Lambda.
1 parent 53572ef commit 857af6d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pip install moesif_aws_lambda
2626

2727
```python
2828
from moesif_aws_lambda.middleware import MoesifLogger
29+
import json
2930

3031
moesif_options = {
3132
'LOG_BODY': True
@@ -36,15 +37,17 @@ def lambda_handler(event, context):
3637
return {
3738
'statusCode': 200,
3839
'isBase64Encoded': False,
39-
'body': {
40+
'body': json.dumps({
4041
'msg': 'Hello from Lambda!'
41-
},
42+
}),
4243
'headers': {
4344
'Content-Type': 'application/json'
4445
}
4546
}
4647
```
4748

49+
> __Important:__ Make sure you set the `body` field to a JSON-formatted string using `json.dumps()`. Otherwise, API Gateway returns a `502 Bad Gateway` error response.
50+
4851
### 2. Set MOESIF_APPLICATION_ID environment variable
4952

5053
Add a new environment variable with the name `MOESIF_APPLICATION_ID` and the value being your Moesif application id,
@@ -55,7 +58,10 @@ You can always find your Moesif Application Id at any time by logging
5558
into the [_Moesif Portal_](https://www.moesif.com/), click on the top right menu,
5659
and then clicking _Installation_.
5760

58-
### 3. Trigger your API
61+
### 3. Deploy your Lambda function
62+
To deploy your Lambda function code with Moesif AWS Lambda middleware, you must archive them in a zip file. For archiving instructions, see our [example Lambda function repository](https://github.com/Moesif/moesif-aws-lambda-python-example?tab=readme-ov-file#how-to-run-this-example). Then follow the instructions in [AWS Lambda docs to upload and deploy your Lambda function code as a zip file archive](https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-zip.html).
63+
64+
### 4. Trigger your API
5965
Grab the URL to your API Gateway or LB and make some calls using a tool like Postman or CURL.
6066

6167
> In order for your event to log to Moesif, you must test using the Amazon API Gateway trigger. Do not invoke your lambda directly using AWS Console as the payload won't contain a valid HTTP payload.

0 commit comments

Comments
 (0)