|
1 | 1 | # Smithy Rust Server SDK examples
|
2 | 2 |
|
3 |
| -This folder contains an example services showcasing the service framework capabilities and to run benchmarks. |
| 3 | +This folder contains some example services showcasing Smithy Rust Server SDK, |
| 4 | +also known as the Rust service framework, capabilities and to run benchmarks. |
4 | 5 |
|
5 |
| -- `/pokemon-service`, a HTTP server implementation demonstrating [middleware](https://awslabs.github.io/smithy-rs/design/server/middleware.html) |
6 |
| -and [extractors](https://awslabs.github.io/smithy-rs/design/server/from_parts.html). |
7 |
| -- `/pokemon-service-tls`, a minimal HTTPS server implementation. |
8 |
| -- `/pokemon-service-lambda`, a minimal Lambda deployment. |
| 6 | +Three server implementations are available: |
9 | 7 |
|
10 |
| -The `/{binary}/tests` folders are integration tests involving the generated clients. |
| 8 | +- `/pokemon-service`, a HTTP server demonstrating [middleware] and [extractors]. |
| 9 | +- `/pokemon-service-tls`, a HTTPS server. This server can do |
| 10 | + its own TLS negotiation, rather than relying on a load balancer. |
| 11 | +- `/pokemon-service-lambda`, a server that can be deployed onto AWS Lambda. |
11 | 12 |
|
12 |
| -## Build |
| 13 | +These servers, and their clients, are generated using smithy-rs. You're invited |
| 14 | +to benchmark the performance of these servers to see whether smithy-rs might be |
| 15 | +a suitable choice for implementing your web service. |
13 | 16 |
|
14 |
| -Since this example requires both the server and client SDK to be code-generated |
| 17 | +[middleware]: https://awslabs.github.io/smithy-rs/design/server/middleware.html |
| 18 | +[extractors]: https://awslabs.github.io/smithy-rs/design/server/from_parts.html |
| 19 | + |
| 20 | + |
| 21 | +## Pre-requisites |
| 22 | + |
| 23 | +You will need install Java 11 to run the smithy-rs code generator and an |
| 24 | +installation of Rust, including `cargo`, to compile the generated code. |
| 25 | + |
| 26 | +(Optional) The [Cargo Lambda](https://cargo-lambda.info/) sub-command for |
| 27 | +`cargo` is required to support the AWS Lambda integration. |
| 28 | + |
| 29 | + |
| 30 | +## Building |
| 31 | + |
| 32 | +Since these examples require both the server and client SDK to be code-generated |
15 | 33 | from their [model](/codegen-server-test/model/pokemon.smithy), a Makefile is
|
16 | 34 | provided to build and run the service. Just run `make` to prepare the first
|
17 | 35 | build.
|
18 | 36 |
|
19 | 37 | Once the example has been built successfully the first time, idiomatic `cargo`
|
20 | 38 | can be used directly.
|
21 | 39 |
|
22 |
| -`make distclean` can be used for a complete cleanup of all artefacts. |
| 40 | +### Make targets: |
| 41 | + |
| 42 | +- `codegen`: generates the Pokémon service crates (default) |
| 43 | +- `build`: compiles the generated client and server |
| 44 | +- `clean`: deletes build artifacts |
| 45 | +- `clippy`: lints the code |
| 46 | +- `distclean`: delete generated code and build artifacts |
| 47 | +- `doc-open`: builds and opens the rustdoc documentation |
| 48 | +- `lambda_invoke`: invokes a running server |
| 49 | +- `lambda_watch`: runs the service on an emulated AWS Lambda environment |
| 50 | +- `run`: runs the Pokémon service |
| 51 | +- `test`: runs integration and unit tests |
| 52 | + |
23 | 53 |
|
24 |
| -## Run |
| 54 | +## Running services |
25 | 55 |
|
26 |
| -To run a binary use |
| 56 | +To run one of the three server implementations locally, provide the appropriate |
| 57 | +service name to the `--bin` flag: |
27 | 58 |
|
28 | 59 | ```bash
|
29 |
| -cargo run -p $BINARY |
| 60 | +cargo run --bin pokemon-service[(-lambda|-tls)] |
30 | 61 | ```
|
31 | 62 |
|
32 |
| -CLI arguments can be passed to the servers, use |
| 63 | +CLI arguments can be passed to the server binaries by adding them after `--`. |
| 64 | +For example, to see a service's help information, use the following: |
33 | 65 |
|
34 | 66 | ```bash
|
35 |
| -cargo run -p $BINARY -- --help |
| 67 | +cargo run --bin <service> -- --help |
36 | 68 | ```
|
37 | 69 |
|
38 |
| -for more information. |
| 70 | +## Testing |
39 | 71 |
|
40 |
| -## Test |
| 72 | +The `/pokemon-test*/tests` folders provide integration tests involving the |
| 73 | +generated clients. |
41 | 74 |
|
42 |
| -`cargo test` can be used to spawn a service and run some simple integration |
43 |
| -tests against it. Use `-p $BINARY` to filter by package. |
| 75 | +They can be invoked with `cargo test`. This will spawn each service in turn |
| 76 | +and run some integration tests against it. Use `-p <package>` to filter by |
| 77 | +package. |
44 | 78 |
|
45 | 79 | More info can be found in the `tests` folder of each package.
|
46 | 80 |
|
47 |
| -## Benchmarks |
48 | 81 |
|
49 |
| -Please see [BENCHMARKS.md](/examples/BENCHMARKS.md). |
| 82 | +## Benchmarking |
| 83 | + |
| 84 | +Servers running locally (see "Running services") can be benchmarked with any |
| 85 | +load testing tool, such as Artillery or `wrk`. |
| 86 | + |
| 87 | +Please see [BENCHMARKS.md](/examples/BENCHMARKS.md) for benchmarking results |
| 88 | +produced by the smithy-rs team. |
0 commit comments