Skip to content

Commit 42ec72d

Browse files
committed
Add cargo lambda example
1 parent 892c1fe commit 42ec72d

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cargo.lock
2+
/target
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "axum-on-aws-lambda"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# Starting in Rust 1.62 you can use `cargo add` to add dependencies
7+
# to your project.
8+
#
9+
# If you're using an older Rust version,
10+
# download cargo-edit(https://github.com/killercup/cargo-edit#installation)
11+
# to install the `add` subcommand.
12+
#
13+
# Running `cargo add DEPENDENCY_NAME` will
14+
# add the latest version of a dependency to the list,
15+
# and it will keep the alphabetic ordering for you.
16+
17+
[dependencies]
18+
lambda_http = "0.7"
19+
lambda_runtime = "0.7"
20+
tokio = { version = "1", features = ["macros"] }
21+
axum = "0.6"
22+
serde_json = "1"
23+
#tracing = { version = "0.1", features = ["log"] }
24+
#tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
25+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use lambda_http::{Error, run};
2+
use axum::{extract::Path, response::Json, routing::{get, post}, Router};
3+
use serde_json::{Value, json};
4+
5+
async fn index() -> Json<Value> {
6+
Json(json!({ "msg": "Hello, Sydney!" }))
7+
}
8+
9+
async fn greet(Path(name): Path<String>) -> Json<Value> {
10+
Json(json!({ "msg": format!("Hello, {name}!") }))
11+
}
12+
13+
14+
#[tokio::main]
15+
async fn main() -> Result<(), Error> {
16+
let app = Router::new()
17+
.route("/", get(index))
18+
.route("/:name", post(greet));
19+
20+
run(app).await
21+
}

0 commit comments

Comments
 (0)