Skip to content

Commit 40a0a67

Browse files
committed
2. Handle REST API requests (implement Lambda functions)
1 parent 099edfd commit 40a0a67

File tree

26 files changed

+3516
-52
lines changed

26 files changed

+3516
-52
lines changed

.github/workflows/doc.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Deploy Tutorial Site to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
pages: write
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout Repository
18+
uses: actions/checkout@v3
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: "20" # Use the Node version you prefer
24+
25+
- name: Install Dependencies
26+
run: cd doc && npm ci
27+
28+
- name: Build the VitePress Site
29+
run: cd doc && npm run build
30+
# This command builds the site into doc/.vitepress/dist
31+
32+
- name: Deploy to GitHub Pages
33+
uses: peaceiris/actions-gh-pages@v3
34+
with:
35+
github_token: ${{ secrets.GITHUB_TOKEN }}
36+
publish_dir: ./doc/.vitepress/dist

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"cSpell.words": [
3+
"github",
4+
"Korolev",
5+
"peaceiris",
6+
"serde",
7+
"tokio",
8+
"vitepress"
9+
]
10+
}

Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@ members = [
66
"app/functions/function_two",
77
"app/functions/function_three",
88
# libraries
9-
"app/libraries/common_lib",
9+
"app/libraries/lambda_http_wrapper",
1010
]
11+
12+
[workspace.dependencies]
13+
serde = { version = "1.0", features = ["derive"] }
14+
serde_json = "1.0"
15+
lambda_runtime = "0.13.0"
16+
aws_lambda_events = "0.16.0"
17+
lambda_http = "0.14.0"
18+
tokio = { version = "1.0", features = ["macros"] }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# AWS Lambda with Rust runtime
22

3-
This is tutorial project. Read here - [doc/tutorial.md](/doc/tutorial.md)
3+
This is tutorial project. Read here - [Tutorial - AWS Lambda with Rust runtime](/doc/)

app/functions/function_one/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ name = "function_one"
88
path = "src/function_one.rs"
99

1010
[dependencies]
11+
tokio = { workspace = true }
12+
serde = { workspace = true }
13+
14+
# internal dependencies
15+
lambda_http_wrapper = { path = "../../libraries/lambda_http_wrapper"}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
fn main() {
2-
println!("Hello, world!");
1+
use lambda_http_wrapper::Error;
2+
3+
use lambda_http_wrapper::run;
4+
5+
mod function_one_controller;
6+
use function_one_controller::function_one_controller;
7+
mod function_one_types;
8+
9+
#[tokio::main]
10+
async fn main() -> Result<(), Error> {
11+
run(function_one_controller).await
312
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use crate::function_one_types::*;
2+
3+
/// This is “business logic” controller
4+
pub(crate) async fn function_one_controller(req: Request) -> Result<Response, ErrorResponse> {
5+
// For example, get a "name" from the query string (defaulting to "world")
6+
let name = req.name;
7+
8+
// Here you would call into your service layer, etc.
9+
Ok(Response {
10+
message: format!("[Function_1] Hello {}, this is an AWS Lambda HTTP request using controller wrapper to avoid lots of boilerplate", name),
11+
})
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! This module defines the “API types” that your controllers use.
2+
3+
use serde::{Deserialize, Serialize};
4+
5+
/// Your application’s Request – you can add more fields as needed (e.g. headers, body).
6+
#[derive(Debug, Serialize, Deserialize)]
7+
pub struct Request {
8+
/// For simplicity we extract just the query parameters.
9+
pub name: String,
10+
}
11+
12+
/// Your successful Response.
13+
#[derive(Debug, Serialize, Deserialize)]
14+
pub struct Response {
15+
pub message: String,
16+
}
17+
18+
/// Your Error Response.
19+
#[derive(Debug, Serialize, Deserialize)]
20+
pub struct ErrorResponse {
21+
pub error: String,
22+
}

app/functions/function_three/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ name = "function_three"
88
path = "src/function_three.rs"
99

1010
[dependencies]
11+
tokio = { workspace = true }
12+
serde = { workspace = true }
13+
14+
# internal dependencies
15+
lambda_http_wrapper = { path = "../../libraries/lambda_http_wrapper"}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
fn main() {
2-
println!("Hello, world!");
1+
use lambda_http_wrapper::Error;
2+
3+
use lambda_http_wrapper::run_no_input as run;
4+
5+
mod function_three_controller;
6+
use function_three_controller::function_three_controller;
7+
mod function_three_types;
8+
9+
#[tokio::main]
10+
async fn main() -> Result<(), Error> {
11+
run(function_three_controller).await
312
}

0 commit comments

Comments
 (0)