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: readme.md
+43Lines changed: 43 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -294,6 +294,49 @@ try await runtime.run()
294
294
295
295
You can learn how to deploy and invoke this function in [the background tasks example README file](Examples/BackgroundTasks/README.md).
296
296
297
+
## Testing Locally
298
+
299
+
Before deploying your code to AWS Lambda, you can test it locally by running the executable target on your local machine. It will look like this on CLI:
300
+
301
+
```sh
302
+
swift run
303
+
```
304
+
305
+
When not running inside a Lambda execution environment, it 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`.
306
+
307
+
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.
308
+
309
+
Then we use curl to invoke the local endpoint with the test JSON payload.
By default, when using the local Lambda server, it listens on the `/invoke` endpoint.
331
+
332
+
Some testing tools, such as the [AWS Lambda runtime interface emulator](https://docs.aws.amazon.com/lambda/latest/dg/images-test.html), require a different endpoint. In that case, you can use the `LOCAL_LAMBDA_SERVER_INVOCATION_ENDPOINT` environment variable to force the runtime to listen on a different endpoint.
333
+
334
+
Example:
335
+
336
+
```sh
337
+
LOCAL_LAMBDA_SERVER_INVOCATION_ENDPOINT=/2015-03-31/functions/function/invocations swift run
0 commit comments