Skip to content

Commit 2dedba8

Browse files
authored
Move examples to a central directory (#487)
* Move examples to a central directory Signed-off-by: David Calavera <[email protected]> * Remove duplicated gitignore files. Signed-off-by: David Calavera <[email protected]>
1 parent 4217f51 commit 2dedba8

File tree

54 files changed

+633
-331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+633
-331
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ jobs:
8181
- name: Run clippy check
8282
run: cargo clippy
8383

84+
check-examples:
85+
runs-on: ubuntu-latest
86+
steps:
87+
- uses: actions/checkout@v1
88+
- uses: actions-rs/toolchain@v1
89+
with:
90+
toolchain: stable
91+
components: clippy
92+
override: true
93+
- name: Check examples
94+
working-directory: examples
95+
shell: bash
96+
run: ./check-examples.sh
97+
8498
# publish rustdoc to a gh-pages branch on pushes to main
8599
# this can be helpful to those depending on the mainline branch
86100
publish-docs:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/target
1+
target
22
/.cargo
33
lambda-runtime/libtest.rmeta
44
lambda-integration-tests/target

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ members = [
55
"lambda-runtime-api-client",
66
"lambda-runtime",
77
"lambda-extension"
8-
]
8+
]
9+
10+
exclude = ["examples"]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "error-handling"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
7+
# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
8+
# to manage dependencies.
9+
# Running `cargo add DEPENDENCY_NAME` will
10+
# add the latest version of a dependency to the list,
11+
# and it will keep the alphabetic ordering for you.
12+
13+
[dependencies]
14+
lambda_runtime = { path = "../../lambda-runtime" }
15+
serde = "1.0.136"
16+
serde_json = "1.0.81"
17+
simple-error = "0.2.3"
18+
tokio = { version = "1", features = ["macros"] }
19+
tracing = { version = "0.1", features = ["log"] }
20+
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
21+
22+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# AWS Lambda Function example
2+
3+
## Build & Deploy
4+
5+
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6+
2. Build the function with `cargo lambda build --release`
7+
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
8+
9+
## Build for ARM 64
10+
11+
Build the function with `cargo lambda build --release --arm64`

lambda-runtime/examples/error-handling.rs renamed to examples/basic-error-handling/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ async fn main() -> Result<(), Error> {
5353
// While `tracing` is used internally, `log` can be used as well if preferred.
5454
tracing_subscriber::fmt()
5555
.with_max_level(tracing::Level::INFO)
56-
// this needs to be set to false, otherwise ANSI color codes will
57-
// show up in a confusing manner in CloudWatch logs.
58-
.with_ansi(false)
5956
// disabling time is handy because CloudWatch will add the ingestion time.
6057
.without_time()
6158
.init();

examples/basic-lambda/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "basic-lambda"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
7+
# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
8+
# to manage dependencies.
9+
# Running `cargo add DEPENDENCY_NAME` will
10+
# add the latest version of a dependency to the list,
11+
# and it will keep the alphabetic ordering for you.
12+
13+
[dependencies]
14+
lambda_runtime = { path = "../../lambda-runtime" }
15+
serde = "1.0.136"
16+
tokio = { version = "1", features = ["macros"] }
17+
tracing = { version = "0.1", features = ["log"] }
18+
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
19+
20+

examples/basic-lambda/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# AWS Lambda Function example
2+
3+
## Build & Deploy
4+
5+
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6+
2. Build the function with `cargo lambda build --release`
7+
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
8+
9+
## Build for ARM 64
10+
11+
Build the function with `cargo lambda build --release --arm64`

lambda-runtime/examples/basic.rs renamed to examples/basic-lambda/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ struct Response {
2626
async fn main() -> Result<(), Error> {
2727
tracing_subscriber::fmt()
2828
.with_max_level(tracing::Level::INFO)
29-
// this needs to be set to false, otherwise ANSI color codes will
30-
// show up in a confusing manner in CloudWatch logs.
31-
.with_ansi(false)
3229
// disabling time is handy because CloudWatch will add the ingestion time.
3330
.without_time()
3431
.init();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "shared-resource"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
7+
# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
8+
# to manage dependencies.
9+
# Running `cargo add DEPENDENCY_NAME` will
10+
# add the latest version of a dependency to the list,
11+
# and it will keep the alphabetic ordering for you.
12+
13+
[dependencies]
14+
lambda_runtime = { path = "../../lambda-runtime" }
15+
serde = "1.0.136"
16+
tokio = { version = "1", features = ["macros"] }
17+
tracing = { version = "0.1", features = ["log"] }
18+
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
19+
20+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# AWS Lambda Function example
2+
3+
## Build & Deploy
4+
5+
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6+
2. Build the function with `cargo lambda build --release`
7+
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`
8+
9+
## Build for ARM 64
10+
11+
Build the function with `cargo lambda build --release --arm64`

lambda-runtime/examples/shared_resource.rs renamed to examples/basic-shared-resource/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ async fn main() -> Result<(), Error> {
4747
// required to enable CloudWatch error logging by the runtime
4848
tracing_subscriber::fmt()
4949
.with_max_level(tracing::Level::INFO)
50-
// this needs to be set to false, otherwise ANSI color codes will
51-
// show up in a confusing manner in CloudWatch logs.
52-
.with_ansi(false)
5350
// disabling time is handy because CloudWatch will add the ingestion time.
5451
.without_time()
5552
.init();

examples/check-examples.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
for f in *; do
5+
if [ -d "$f" ]; then
6+
echo "==> Checking example: $f"
7+
cd $f
8+
cargo check
9+
cd ..
10+
fi
11+
done

examples/extension-basic/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "extension-basic"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
7+
# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
8+
# to manage dependencies.
9+
# Running `cargo add DEPENDENCY_NAME` will
10+
# add the latest version of a dependency to the list,
11+
# and it will keep the alphabetic ordering for you.
12+
13+
[dependencies]
14+
lambda-extension = { path = "../../lambda-extension" }
15+
serde = "1.0.136"
16+
tokio = { version = "1", features = ["macros"] }
17+
tracing = { version = "0.1", features = ["log"] }
18+
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
19+
20+

examples/extension-basic/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# AWS Lambda Logs extension example
2+
3+
## Build & Deploy
4+
5+
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6+
2. Build the extension with `cargo lambda build --release --extension`
7+
3. Deploy the extension as a layer with `cargo lambda deploy --extension`
8+
9+
The last command will give you an ARN for the extension layer that you can use in your functions.
10+
11+
12+
## Build for ARM 64
13+
14+
Build the extension with `cargo lambda build --release --extension --arm64`

lambda-extension/examples/basic.rs renamed to examples/extension-basic/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ async fn main() -> Result<(), Error> {
1818
// While `tracing` is used internally, `log` can be used as well if preferred.
1919
tracing_subscriber::fmt()
2020
.with_max_level(tracing::Level::INFO)
21-
// this needs to be set to false, otherwise ANSI color codes will
22-
// show up in a confusing manner in CloudWatch logs.
23-
.with_ansi(false)
2421
// disabling time is handy because CloudWatch will add the ingestion time.
2522
.without_time()
2623
.init();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "extension-combined"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
7+
# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
8+
# to manage dependencies.
9+
# Running `cargo add DEPENDENCY_NAME` will
10+
# add the latest version of a dependency to the list,
11+
# and it will keep the alphabetic ordering for you.
12+
13+
[dependencies]
14+
lambda-extension = { path = "../../lambda-extension" }
15+
serde = "1.0.136"
16+
tokio = { version = "1", features = ["macros"] }
17+
tracing = { version = "0.1", features = ["log"] }
18+
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
19+
20+

examples/extension-combined/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# AWS Lambda Logs extension example
2+
3+
## Build & Deploy
4+
5+
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6+
2. Build the extension with `cargo lambda build --release --extension`
7+
3. Deploy the extension as a layer with `cargo lambda deploy --extension`
8+
9+
The last command will give you an ARN for the extension layer that you can use in your functions.
10+
11+
12+
## Build for ARM 64
13+
14+
Build the extension with `cargo lambda build --release --extension --arm64`

lambda-extension/examples/combined.rs renamed to examples/extension-combined/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ async fn main() -> Result<(), Error> {
3333
// While `tracing` is used internally, `log` can be used as well if preferred.
3434
tracing_subscriber::fmt()
3535
.with_max_level(tracing::Level::INFO)
36-
// this needs to be set to false, otherwise ANSI color codes will
37-
// show up in a confusing manner in CloudWatch logs.
38-
.with_ansi(false)
3936
// disabling time is handy because CloudWatch will add the ingestion time.
4037
.without_time()
4138
.init();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "extension-custom-events"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
7+
# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
8+
# to manage dependencies.
9+
# Running `cargo add DEPENDENCY_NAME` will
10+
# add the latest version of a dependency to the list,
11+
# and it will keep the alphabetic ordering for you.
12+
13+
[dependencies]
14+
lambda-extension = { path = "../../lambda-extension" }
15+
serde = "1.0.136"
16+
tokio = { version = "1", features = ["macros"] }
17+
tracing = { version = "0.1", features = ["log"] }
18+
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
19+
20+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# AWS Lambda Logs extension example
2+
3+
## Build & Deploy
4+
5+
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6+
2. Build the extension with `cargo lambda build --release --extension`
7+
3. Deploy the extension as a layer with `cargo lambda deploy --extension`
8+
9+
The last command will give you an ARN for the extension layer that you can use in your functions.
10+
11+
12+
## Build for ARM 64
13+
14+
Build the extension with `cargo lambda build --release --extension --arm64`

lambda-extension/examples/custom_events.rs renamed to examples/extension-custom-events/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ async fn main() -> Result<(), Error> {
2020
// While `tracing` is used internally, `log` can be used as well if preferred.
2121
tracing_subscriber::fmt()
2222
.with_max_level(tracing::Level::INFO)
23-
// this needs to be set to false, otherwise ANSI color codes will
24-
// show up in a confusing manner in CloudWatch logs.
25-
.with_ansi(false)
2623
// disabling time is handy because CloudWatch will add the ingestion time.
2724
.without_time()
2825
.init();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "extension-custom-service"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
7+
# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
8+
# to manage dependencies.
9+
# Running `cargo add DEPENDENCY_NAME` will
10+
# add the latest version of a dependency to the list,
11+
# and it will keep the alphabetic ordering for you.
12+
13+
[dependencies]
14+
lambda-extension = { path = "../../lambda-extension" }
15+
serde = "1.0.136"
16+
tokio = { version = "1", features = ["macros"] }
17+
tracing = { version = "0.1", features = ["log"] }
18+
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
19+
20+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# AWS Lambda Logs extension example
2+
3+
## Build & Deploy
4+
5+
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6+
2. Build the extension with `cargo lambda build --release --extension`
7+
3. Deploy the extension as a layer with `cargo lambda deploy --extension`
8+
9+
The last command will give you an ARN for the extension layer that you can use in your functions.
10+
11+
12+
## Build for ARM 64
13+
14+
Build the extension with `cargo lambda build --release --extension --arm64`

lambda-extension/examples/custom_service.rs renamed to examples/extension-custom-service/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ async fn main() -> Result<(), Error> {
3737
// While `tracing` is used internally, `log` can be used as well if preferred.
3838
tracing_subscriber::fmt()
3939
.with_max_level(tracing::Level::INFO)
40-
// this needs to be set to false, otherwise ANSI color codes will
41-
// show up in a confusing manner in CloudWatch logs.
42-
.with_ansi(false)
4340
// disabling time is handy because CloudWatch will add the ingestion time.
4441
.without_time()
4542
.init();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "extension-logs-basic"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
7+
# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
8+
# to manage dependencies.
9+
# Running `cargo add DEPENDENCY_NAME` will
10+
# add the latest version of a dependency to the list,
11+
# and it will keep the alphabetic ordering for you.
12+
13+
[dependencies]
14+
lambda-extension = { path = "../../lambda-extension" }
15+
serde = "1.0.136"
16+
tokio = { version = "1", features = ["macros", "rt"] }
17+
tracing = { version = "0.1", features = ["log"] }
18+
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
19+
20+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# AWS Lambda Logs extension example
2+
3+
## Build & Deploy
4+
5+
1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
6+
2. Build the extension with `cargo lambda build --release --extension`
7+
3. Deploy the extension as a layer with `cargo lambda deploy --extension`
8+
9+
The last command will give you an ARN for the extension layer that you can use in your functions.
10+
11+
12+
## Build for ARM 64
13+
14+
Build the extension with `cargo lambda build --release --extension --arm64`

0 commit comments

Comments
 (0)