Skip to content

Move examples to a central directory #487

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 2 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ jobs:
- name: Run clippy check
run: cargo clippy

check-examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true
- name: Check examples
working-directory: examples
shell: bash
run: ./check-examples.sh

# publish rustdoc to a gh-pages branch on pushes to main
# this can be helpful to those depending on the mainline branch
publish-docs:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target
target
/.cargo
lambda-runtime/libtest.rmeta
lambda-integration-tests/target
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ members = [
"lambda-runtime-api-client",
"lambda-runtime",
"lambda-extension"
]
]

exclude = ["examples"]
22 changes: 22 additions & 0 deletions examples/basic-error-handling/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "error-handling"
version = "0.1.0"
edition = "2021"


# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
# to manage dependencies.
# Running `cargo add DEPENDENCY_NAME` will
# add the latest version of a dependency to the list,
# and it will keep the alphabetic ordering for you.

[dependencies]
lambda_runtime = { path = "../../lambda-runtime" }
serde = "1.0.136"
serde_json = "1.0.81"
simple-error = "0.2.3"
tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }


11 changes: 11 additions & 0 deletions examples/basic-error-handling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AWS Lambda Function example

## Build & Deploy

1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
2. Build the function with `cargo lambda build --release`
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`

## Build for ARM 64

Build the function with `cargo lambda build --release --arm64`
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ async fn main() -> Result<(), Error> {
// While `tracing` is used internally, `log` can be used as well if preferred.
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
// this needs to be set to false, otherwise ANSI color codes will
// show up in a confusing manner in CloudWatch logs.
.with_ansi(false)
// disabling time is handy because CloudWatch will add the ingestion time.
.without_time()
.init();
Expand Down
20 changes: 20 additions & 0 deletions examples/basic-lambda/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "basic-lambda"
version = "0.1.0"
edition = "2021"


# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
# to manage dependencies.
# Running `cargo add DEPENDENCY_NAME` will
# add the latest version of a dependency to the list,
# and it will keep the alphabetic ordering for you.

[dependencies]
lambda_runtime = { path = "../../lambda-runtime" }
serde = "1.0.136"
tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }


11 changes: 11 additions & 0 deletions examples/basic-lambda/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AWS Lambda Function example

## Build & Deploy

1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
2. Build the function with `cargo lambda build --release`
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`

## Build for ARM 64

Build the function with `cargo lambda build --release --arm64`
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ struct Response {
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
// this needs to be set to false, otherwise ANSI color codes will
// show up in a confusing manner in CloudWatch logs.
.with_ansi(false)
// disabling time is handy because CloudWatch will add the ingestion time.
.without_time()
.init();
Expand Down
20 changes: 20 additions & 0 deletions examples/basic-shared-resource/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "shared-resource"
version = "0.1.0"
edition = "2021"


# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
# to manage dependencies.
# Running `cargo add DEPENDENCY_NAME` will
# add the latest version of a dependency to the list,
# and it will keep the alphabetic ordering for you.

[dependencies]
lambda_runtime = { path = "../../lambda-runtime" }
serde = "1.0.136"
tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }


11 changes: 11 additions & 0 deletions examples/basic-shared-resource/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AWS Lambda Function example

## Build & Deploy

1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
2. Build the function with `cargo lambda build --release`
3. Deploy the function to AWS Lambda with `cargo lambda deploy --iam-role YOUR_ROLE`

## Build for ARM 64

Build the function with `cargo lambda build --release --arm64`
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ async fn main() -> Result<(), Error> {
// required to enable CloudWatch error logging by the runtime
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
// this needs to be set to false, otherwise ANSI color codes will
// show up in a confusing manner in CloudWatch logs.
.with_ansi(false)
// disabling time is handy because CloudWatch will add the ingestion time.
.without_time()
.init();
Expand Down
11 changes: 11 additions & 0 deletions examples/check-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e

for f in *; do
if [ -d "$f" ]; then
echo "==> Checking example: $f"
cd $f
cargo check
cd ..
fi
done
20 changes: 20 additions & 0 deletions examples/extension-basic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "extension-basic"
version = "0.1.0"
edition = "2021"


# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
# to manage dependencies.
# Running `cargo add DEPENDENCY_NAME` will
# add the latest version of a dependency to the list,
# and it will keep the alphabetic ordering for you.

[dependencies]
lambda-extension = { path = "../../lambda-extension" }
serde = "1.0.136"
tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }


14 changes: 14 additions & 0 deletions examples/extension-basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# AWS Lambda Logs extension example

## Build & Deploy

1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
2. Build the extension with `cargo lambda build --release --extension`
3. Deploy the extension as a layer with `cargo lambda deploy --extension`

The last command will give you an ARN for the extension layer that you can use in your functions.


## Build for ARM 64

Build the extension with `cargo lambda build --release --extension --arm64`
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ async fn main() -> Result<(), Error> {
// While `tracing` is used internally, `log` can be used as well if preferred.
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
// this needs to be set to false, otherwise ANSI color codes will
// show up in a confusing manner in CloudWatch logs.
.with_ansi(false)
// disabling time is handy because CloudWatch will add the ingestion time.
.without_time()
.init();
Expand Down
20 changes: 20 additions & 0 deletions examples/extension-combined/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "extension-combined"
version = "0.1.0"
edition = "2021"


# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
# to manage dependencies.
# Running `cargo add DEPENDENCY_NAME` will
# add the latest version of a dependency to the list,
# and it will keep the alphabetic ordering for you.

[dependencies]
lambda-extension = { path = "../../lambda-extension" }
serde = "1.0.136"
tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }


14 changes: 14 additions & 0 deletions examples/extension-combined/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# AWS Lambda Logs extension example

## Build & Deploy

1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
2. Build the extension with `cargo lambda build --release --extension`
3. Deploy the extension as a layer with `cargo lambda deploy --extension`

The last command will give you an ARN for the extension layer that you can use in your functions.


## Build for ARM 64

Build the extension with `cargo lambda build --release --extension --arm64`
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ async fn main() -> Result<(), Error> {
// While `tracing` is used internally, `log` can be used as well if preferred.
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
// this needs to be set to false, otherwise ANSI color codes will
// show up in a confusing manner in CloudWatch logs.
.with_ansi(false)
// disabling time is handy because CloudWatch will add the ingestion time.
.without_time()
.init();
Expand Down
20 changes: 20 additions & 0 deletions examples/extension-custom-events/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "extension-custom-events"
version = "0.1.0"
edition = "2021"


# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
# to manage dependencies.
# Running `cargo add DEPENDENCY_NAME` will
# add the latest version of a dependency to the list,
# and it will keep the alphabetic ordering for you.

[dependencies]
lambda-extension = { path = "../../lambda-extension" }
serde = "1.0.136"
tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }


14 changes: 14 additions & 0 deletions examples/extension-custom-events/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# AWS Lambda Logs extension example

## Build & Deploy

1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
2. Build the extension with `cargo lambda build --release --extension`
3. Deploy the extension as a layer with `cargo lambda deploy --extension`

The last command will give you an ARN for the extension layer that you can use in your functions.


## Build for ARM 64

Build the extension with `cargo lambda build --release --extension --arm64`
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ async fn main() -> Result<(), Error> {
// While `tracing` is used internally, `log` can be used as well if preferred.
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
// this needs to be set to false, otherwise ANSI color codes will
// show up in a confusing manner in CloudWatch logs.
.with_ansi(false)
// disabling time is handy because CloudWatch will add the ingestion time.
.without_time()
.init();
Expand Down
20 changes: 20 additions & 0 deletions examples/extension-custom-service/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "extension-custom-service"
version = "0.1.0"
edition = "2021"


# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
# to manage dependencies.
# Running `cargo add DEPENDENCY_NAME` will
# add the latest version of a dependency to the list,
# and it will keep the alphabetic ordering for you.

[dependencies]
lambda-extension = { path = "../../lambda-extension" }
serde = "1.0.136"
tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }


14 changes: 14 additions & 0 deletions examples/extension-custom-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# AWS Lambda Logs extension example

## Build & Deploy

1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
2. Build the extension with `cargo lambda build --release --extension`
3. Deploy the extension as a layer with `cargo lambda deploy --extension`

The last command will give you an ARN for the extension layer that you can use in your functions.


## Build for ARM 64

Build the extension with `cargo lambda build --release --extension --arm64`
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ async fn main() -> Result<(), Error> {
// While `tracing` is used internally, `log` can be used as well if preferred.
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
// this needs to be set to false, otherwise ANSI color codes will
// show up in a confusing manner in CloudWatch logs.
.with_ansi(false)
// disabling time is handy because CloudWatch will add the ingestion time.
.without_time()
.init();
Expand Down
20 changes: 20 additions & 0 deletions examples/extension-logs-basic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "extension-logs-basic"
version = "0.1.0"
edition = "2021"


# Use cargo-edit(https://github.com/killercup/cargo-edit#installation)
# to manage dependencies.
# Running `cargo add DEPENDENCY_NAME` will
# add the latest version of a dependency to the list,
# and it will keep the alphabetic ordering for you.

[dependencies]
lambda-extension = { path = "../../lambda-extension" }
serde = "1.0.136"
tokio = { version = "1", features = ["macros", "rt"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }


14 changes: 14 additions & 0 deletions examples/extension-logs-basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# AWS Lambda Logs extension example

## Build & Deploy

1. Install [cargo-lambda](https://github.com/cargo-lambda/cargo-lambda#installation)
2. Build the extension with `cargo lambda build --release --extension`
3. Deploy the extension as a layer with `cargo lambda deploy --extension`

The last command will give you an ARN for the extension layer that you can use in your functions.


## Build for ARM 64

Build the extension with `cargo lambda build --release --extension --arm64`
Loading