|
1 | | -## How to update the base template |
| 1 | +# Introduction |
2 | 2 |
|
3 | | -If you want to update the base template this is the process (unfortunately Mailchimp makes it a bit tricky): |
| 3 | +create-issuev2 is a Rust project that implements an AWS Lambda function in Rust. |
4 | 4 |
|
5 | | -- Update the file `functions/create-issue/templates/newsletter.njk` and apply the desired changes |
6 | | -- Run the tests with `node_modules/.bin/vitest run functions/create-issue/ -u` (from the root of the project) |
7 | | -- Now the file `functions/create-issue/__tests__/__snapshots__/template.html` is up to date. Copy its code. |
8 | | -- In Mailchimp edit the saved template and paste the code |
9 | | -- Check that the preview renders as expected and save |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- [Rust](https://www.rust-lang.org/tools/install) |
| 8 | +- [Cargo Lambda](https://www.cargo-lambda.info/guide/installation.html) |
| 9 | + |
| 10 | +## Building |
| 11 | + |
| 12 | +To build the project for production, run `cargo lambda build --release`. Remove the `--release` flag to build for development. |
| 13 | + |
| 14 | +Read more about building your lambda function in [the Cargo Lambda documentation](https://www.cargo-lambda.info/commands/build.html). |
| 15 | + |
| 16 | +## Testing |
| 17 | + |
| 18 | +You can run regular Rust unit tests with `cargo test`. |
| 19 | + |
| 20 | +If you want to run integration tests locally, you can use the `cargo lambda watch` and `cargo lambda invoke` commands to do it. |
| 21 | + |
| 22 | +First, run `cargo lambda watch` to start a local server. When you make changes to the code, the server will automatically restart. |
| 23 | + |
| 24 | +Second, you'll need a way to pass the event data to the lambda function. |
| 25 | + |
| 26 | +You can use the existent [event payloads](https://github.com/awslabs/aws-lambda-rust-runtime/tree/main/lambda-events/src/fixtures) in the Rust Runtime repository if your lambda function is using one of the supported event types. |
| 27 | + |
| 28 | +You can use those examples directly with the `--data-example` flag, where the value is the name of the file in the [lambda-events](https://github.com/awslabs/aws-lambda-rust-runtime/tree/main/lambda-events/src/fixtures) repository without the `example_` prefix and the `.json` extension. |
| 29 | + |
| 30 | +```bash |
| 31 | +cargo lambda invoke --data-example apigw-request |
| 32 | +``` |
| 33 | + |
| 34 | +For generic events, where you define the event data structure, you can create a JSON file with the data you want to test with. For example: |
| 35 | + |
| 36 | +```json |
| 37 | +{ |
| 38 | + "command": "test" |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +Then, run `cargo lambda invoke --data-file ./data.json` to invoke the function with the data in `data.json`. |
| 43 | + |
| 44 | + |
| 45 | +Read more about running the local server in [the Cargo Lambda documentation for the `watch` command](https://www.cargo-lambda.info/commands/watch.html). |
| 46 | +Read more about invoking the function in [the Cargo Lambda documentation for the `invoke` command](https://www.cargo-lambda.info/commands/invoke.html). |
| 47 | + |
| 48 | +## Deploying |
| 49 | + |
| 50 | +To deploy the project, run `cargo lambda deploy`. This will create an IAM role and a Lambda function in your AWS account. |
| 51 | + |
| 52 | +Read more about deploying your lambda function in [the Cargo Lambda documentation](https://www.cargo-lambda.info/commands/deploy.html). |
0 commit comments