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 <david.calavera@gmail.com> * Remove duplicated gitignore files. Signed-off-by: David Calavera <david.calavera@gmail.com>
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+

0 commit comments

Comments
 (0)