Skip to content

add local testing instructions to hello world example #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Examples/HelloWorld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@ The handler is `(event: String, context: LambdaContext)`. The function takes two

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

## Test locally

You can test your function locally before deploying it to AWS Lambda.

To start the local function, type the following commands:

```bash
swift run
```

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.

```txt
Building for debugging...
[1/1] Write swift-version--644A47CB88185983.txt
Build of product 'MyLambda' complete! (0.31s)
2025-01-29T12:44:48+0100 info LocalServer : host="127.0.0.1" port=7000 [AWSLambdaRuntimeCore] Server started and listening
```

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.

```bash
curl -d '"seb"' http://127.0.0.1:7000/invoke
"Hello seb"
```

> [!IMPORTANT]
> The local server is only available in `DEBUG` mode. It will not start with `swift -c release run`.

## Build & Package

To build & archive the package, type the following commands.
Expand Down