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
Add tracing of request events + mention LOG_LEVEL in README (#315)
* add tracing of request events + mention LOG_LEVEL in README
* fix typo
Co-authored-by: Mahdi Bahrami <[email protected]>
* clarify the use of env variable and the swift cli
Co-authored-by: Mahdi Bahrami <[email protected]>
* clarify language about HTTP server
Co-authored-by: Mahdi Bahrami <[email protected]>
* formatting
Co-authored-by: Mahdi Bahrami <[email protected]>
* factor in additional suggestions from @MahdiBM
* combine two logger statement into one and print only for Kb of payload
---------
Co-authored-by: Mahdi Bahrami <[email protected]>
Copy file name to clipboardExpand all lines: readme.md
+44
Original file line number
Diff line number
Diff line change
@@ -174,6 +174,50 @@ Next, create a `MyLambda.swift` and implement your Lambda. Note that the file ca
174
174
175
175
Beyond the small cognitive complexity of using the `EventLoopFuture` based APIs, note these APIs should be used with extra care. An `EventLoopLambdaHandler` will execute the user code on the same `EventLoop` (thread) as the library, making processing faster but requiring the user code to never call blocking APIs as it might prevent the underlying process from functioning.
176
176
177
+
## Testing Locally
178
+
179
+
Before deploying your code to AWS Lambda, you can test it locally by setting the `LOCAL_LAMBDA_SERVER_ENABLED` environment variable to true. It will look like this on CLI:
180
+
181
+
```sh
182
+
LOCAL_LAMBDA_SERVER_ENABLED=true swift run
183
+
```
184
+
185
+
This starts a local HTTP server listening on port 7000. You can invoke your local Lambda function by sending an HTTP POST request to `http://127.0.0.1:7000/invoke`.
186
+
187
+
The request must include the JSON payload expected as an `Event` by your function. You can create a text file with the JSON payload documented by AWS or captured from a trace. In this example, we used [the APIGatewayv2 JSON payload from the documentation](https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html#apigateway-example-event), saved as `events/create-session.json` text file.
188
+
189
+
Then we use curl to invoke the local endpoint with the test JSON payload.
You can increase the verbosity of the runtime using the `LOG_LEVEL` environment variable.
212
+
213
+
-`LOG_LEVEL=debug` displays information about the Swift AWS Lambda Runtime activity and lifecycle
214
+
-`LOG_LEVEL=trace` displays a string representation of the input event as received from the AWS Lambda service (before invoking your handler).
215
+
216
+
You can modify the verbosity of a Lambda function by passing the LOG_LEVEL environment variable both during your local testing (LOG_LEVEL=trace LOCAL_LAMBDA_SERVER_ENABLED=true swift run) or when you deploy your code on AWS Lambda.
217
+
You can [define environment variables for your Lambda functions](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html) in the AWS console or programmatically.
218
+
219
+
This repository follows [Swift's Log Level Guidelines](https://www.swift.org/server/guides/libraries/log-levels.html). At `LOG_LEVEL=trace`, the AWS Lambda runtime will display a string representation of the input event as received from the AWS Lambda service before invoking your handler, for maximum debuggability.
220
+
177
221
## Deploying to AWS Lambda
178
222
179
223
To deploy Lambda functions to AWS Lambda, you need to compile the code for Amazon Linux which is the OS used on AWS Lambda microVMs, package it as a Zip file, and upload to AWS.
0 commit comments