Skip to content

Commit dbc2f98

Browse files
authored
add local testing instructions to hello world example (#474)
The local testing instruction are missing from the hello world example. The format of the payload is not intuitive or trivial to guess. We need to make it explicit
1 parent 7aa746f commit dbc2f98

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Examples/HelloWorld/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,35 @@ The handler is `(event: String, context: LambdaContext)`. The function takes two
1212

1313
The function return value will be encoded as your Lambda function response.
1414

15+
## Test locally
16+
17+
You can test your function locally before deploying it to AWS Lambda.
18+
19+
To start the local function, type the following commands:
20+
21+
```bash
22+
swift run
23+
```
24+
25+
It will compile your code and start the local server. You know the local server is ready to accept connections when you see this message.
26+
27+
```txt
28+
Building for debugging...
29+
[1/1] Write swift-version--644A47CB88185983.txt
30+
Build of product 'MyLambda' complete! (0.31s)
31+
2025-01-29T12:44:48+0100 info LocalServer : host="127.0.0.1" port=7000 [AWSLambdaRuntimeCore] Server started and listening
32+
```
33+
34+
Then, from another Terminal, send your payload with `curl`. Note that the payload must be a valid JSON string. In the case of this function that accepts a simple String, it means the String must be wrapped in between double quotes.
35+
36+
```bash
37+
curl -d '"seb"' http://127.0.0.1:7000/invoke
38+
"Hello seb"
39+
```
40+
41+
> [!IMPORTANT]
42+
> The local server is only available in `DEBUG` mode. It will not start with `swift -c release run`.
43+
1544
## Build & Package
1645

1746
To build & archive the package, type the following commands.

0 commit comments

Comments
 (0)