Loading CHANGELOG.next.toml +10 −0 Original line number Diff line number Diff line Loading @@ -107,3 +107,13 @@ Servers now allow requests' ACCEPT header values to be: references = ["smithy-rs#1544"] meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } author = "82marbag" [[smithy-rs]] message = """ There is a canonical and easier way to run smithy-rs on Lambda [see example]. [see example]: https://github.com/awslabs/smithy-rs/blob/main/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs """ references = ["smithy-rs#1551"] meta = { "breaking" = false, "tada" = true, "bug" = false, "target" = "server" } author = "hugobast" rust-runtime/aws-smithy-http-server/Cargo.toml +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ futures-util = { version = "0.3", default-features = false } http = "0.2" http-body = "0.4" hyper = { version = "0.14.12", features = ["server", "http1", "http2", "tcp", "stream"] } lambda_http = "0.6.0" mime = "0.3" nom = "7" pin-project-lite = "0.2" Loading rust-runtime/aws-smithy-http-server/examples/Makefile +6 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,12 @@ doc-open: codegen clean: cargo clean || echo "Unable to run cargo clean" lambda_watch: cargo lambda watch lambda_invoke: cargo lambda invoke pokemon-service-lambda --data-file pokemon-service/tests/fixtures/example-apigw-request.json distclean: clean rm -rf $(SERVER_SDK_DST) $(CLIENT_SDK_DST) Cargo.lock Loading rust-runtime/aws-smithy-http-server/examples/pokemon-service/Cargo.toml +9 −0 Original line number Diff line number Diff line Loading @@ -11,10 +11,19 @@ default-run = "pokemon-service" name = "pokemon-service-tls" path = "src/bin/pokemon-service-tls.rs" [[bin]] name = "pokemon-service" path = "src/main.rs" [[bin]] name = "pokemon-service-lambda" path = "src/lambda.rs" [dependencies] async-stream = "0.3" clap = { version = "~3.2.1", features = ["derive"] } hyper = {version = "0.14.12", features = ["server"] } lambda_http = "0.6.0" rand = "0.8" tokio = "1" tower = "0.4" Loading rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs 0 → 100644 +52 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ // This program is exported as a binary named `pokemon-service-lambda`. use std::sync::Arc; use aws_smithy_http_server::{routing::LambdaHandler, AddExtensionLayer, Router}; use pokemon_service::{ capture_pokemon, empty_operation, get_pokemon_species, get_server_statistics, get_storage, health_check_operation, setup_tracing, State, }; use pokemon_service_server_sdk::operation_registry::OperationRegistryBuilder; use tower::ServiceBuilder; use tower_http::trace::TraceLayer; #[tokio::main] pub async fn main() { setup_tracing(); let app: Router = OperationRegistryBuilder::default() // Build a registry containing implementations to all the operations in the service. These // are async functions or async closures that take as input the operation's input and // return the operation's output. .get_pokemon_species(get_pokemon_species) .get_storage(get_storage) .get_server_statistics(get_server_statistics) .capture_pokemon_operation(capture_pokemon) .empty_operation(empty_operation) .health_check_operation(health_check_operation) .build() .expect("Unable to build operation registry") // Convert it into a router that will route requests to the matching operation // implementation. .into(); // Setup shared state and middlewares. let shared_state = Arc::new(State::default()); let app = app.layer( ServiceBuilder::new() .layer(TraceLayer::new_for_http()) .layer(AddExtensionLayer::new(shared_state)), ); let handler = LambdaHandler::new(app); let lambda = lambda_http::run(handler); if let Err(err) = lambda.await { eprintln!("lambda error: {}", err); } } Loading
CHANGELOG.next.toml +10 −0 Original line number Diff line number Diff line Loading @@ -107,3 +107,13 @@ Servers now allow requests' ACCEPT header values to be: references = ["smithy-rs#1544"] meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } author = "82marbag" [[smithy-rs]] message = """ There is a canonical and easier way to run smithy-rs on Lambda [see example]. [see example]: https://github.com/awslabs/smithy-rs/blob/main/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs """ references = ["smithy-rs#1551"] meta = { "breaking" = false, "tada" = true, "bug" = false, "target" = "server" } author = "hugobast"
rust-runtime/aws-smithy-http-server/Cargo.toml +1 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ futures-util = { version = "0.3", default-features = false } http = "0.2" http-body = "0.4" hyper = { version = "0.14.12", features = ["server", "http1", "http2", "tcp", "stream"] } lambda_http = "0.6.0" mime = "0.3" nom = "7" pin-project-lite = "0.2" Loading
rust-runtime/aws-smithy-http-server/examples/Makefile +6 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,12 @@ doc-open: codegen clean: cargo clean || echo "Unable to run cargo clean" lambda_watch: cargo lambda watch lambda_invoke: cargo lambda invoke pokemon-service-lambda --data-file pokemon-service/tests/fixtures/example-apigw-request.json distclean: clean rm -rf $(SERVER_SDK_DST) $(CLIENT_SDK_DST) Cargo.lock Loading
rust-runtime/aws-smithy-http-server/examples/pokemon-service/Cargo.toml +9 −0 Original line number Diff line number Diff line Loading @@ -11,10 +11,19 @@ default-run = "pokemon-service" name = "pokemon-service-tls" path = "src/bin/pokemon-service-tls.rs" [[bin]] name = "pokemon-service" path = "src/main.rs" [[bin]] name = "pokemon-service-lambda" path = "src/lambda.rs" [dependencies] async-stream = "0.3" clap = { version = "~3.2.1", features = ["derive"] } hyper = {version = "0.14.12", features = ["server"] } lambda_http = "0.6.0" rand = "0.8" tokio = "1" tower = "0.4" Loading
rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs 0 → 100644 +52 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ // This program is exported as a binary named `pokemon-service-lambda`. use std::sync::Arc; use aws_smithy_http_server::{routing::LambdaHandler, AddExtensionLayer, Router}; use pokemon_service::{ capture_pokemon, empty_operation, get_pokemon_species, get_server_statistics, get_storage, health_check_operation, setup_tracing, State, }; use pokemon_service_server_sdk::operation_registry::OperationRegistryBuilder; use tower::ServiceBuilder; use tower_http::trace::TraceLayer; #[tokio::main] pub async fn main() { setup_tracing(); let app: Router = OperationRegistryBuilder::default() // Build a registry containing implementations to all the operations in the service. These // are async functions or async closures that take as input the operation's input and // return the operation's output. .get_pokemon_species(get_pokemon_species) .get_storage(get_storage) .get_server_statistics(get_server_statistics) .capture_pokemon_operation(capture_pokemon) .empty_operation(empty_operation) .health_check_operation(health_check_operation) .build() .expect("Unable to build operation registry") // Convert it into a router that will route requests to the matching operation // implementation. .into(); // Setup shared state and middlewares. let shared_state = Arc::new(State::default()); let app = app.layer( ServiceBuilder::new() .layer(TraceLayer::new_for_http()) .layer(AddExtensionLayer::new(shared_state)), ); let handler = LambdaHandler::new(app); let lambda = lambda_http::run(handler); if let Err(err) = lambda.await { eprintln!("lambda error: {}", err); } }