Skip to content

Commit 99e1e20

Browse files
drganjooFahad Zubairdavid-perez
authored
Add aws-lambda as a feature to generated server SDK (#3648)
## Motivation and Context The generated SDK conditionally re-exports `routing::LambdaHandler` under the feature flag aws-lambda, but the `Cargo.toml` does not define such a feature. ## Description Closes: #3643 ## Checklist - [x] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates --------- Co-authored-by: Fahad Zubair <fahadzub@amazon.com> Co-authored-by: david-perez <d@vidp.dev>
1 parent 6e0f418 commit 99e1e20

File tree

6 files changed

+27
-6
lines changed

6 files changed

+27
-6
lines changed

CHANGELOG.next.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@
99
# message = "Fix typos in module documentation for generated crates"
1010
# references = ["smithy-rs#920"]
1111
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
12-
# author = "rcoh"
12+
# author = "rcoh"
13+
[[smithy-rs]]
14+
message = "A feature, `aws-lambda`, has been added to generated SDKs to re-export types required for Lambda deployment."
15+
references = ["smithy-rs#3643"]
16+
meta = { "breaking" = false, "bug" = true, "tada" = false, "target" = "server" }
17+
author = "drganjoo"

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class ServerRequiredCustomizations : ServerCodegenDecorator {
4848
),
4949
)
5050

51+
rustCrate.mergeFeature(
52+
Feature(
53+
"aws-lambda",
54+
true,
55+
listOf("aws-smithy-http-server/aws-lambda"),
56+
),
57+
)
58+
5159
rustCrate.withModule(ServerRustModule.Types) {
5260
pubUseSmithyPrimitives(codegenContext, codegenContext.model, rustCrate)(this)
5361
rustTemplate(

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerRuntimeTypesReExportsGenerator.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class ServerRuntimeTypesReExportsGenerator(
3838
}
3939
pub mod request {
4040
pub use #{SmithyHttpServer}::request::FromParts;
41+
42+
##[cfg(feature = "aws-lambda")]
43+
pub mod lambda {
44+
pub use #{SmithyHttpServer}::request::lambda::Context;
45+
}
4146
}
4247
pub mod response {
4348
pub use #{SmithyHttpServer}::response::IntoResponse;

examples/pokemon-service-lambda/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ tracing = "0.1"
1919
lambda_http = "0.8.0"
2020

2121
# Local paths
22-
aws-smithy-http-server = { path = "../../rust-runtime/aws-smithy-http-server", features = ["aws-lambda"] }
23-
pokemon-service-server-sdk = { path = "../pokemon-service-server-sdk/" }
22+
aws-smithy-http-server = { path = "../../rust-runtime/aws-smithy-http-server" }
23+
pokemon-service-server-sdk = { path = "../pokemon-service-server-sdk/", features = ["aws-lambda"] }
2424
pokemon-service-common = { path = "../pokemon-service-common/" }

examples/pokemon-service-lambda/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
use std::sync::Arc;
77

8-
use aws_smithy_http_server::{request::lambda::Context, Extension};
8+
use aws_smithy_http_server::Extension;
99

1010
use pokemon_service_common::State;
1111
use pokemon_service_server_sdk::{
1212
error::{GetStorageError, StorageAccessNotAuthorized},
1313
input::GetStorageInput,
1414
output::GetStorageOutput,
15+
server::request::lambda::Context,
1516
};
1617

1718
/// Retrieves the user's storage and logs the lambda request ID.

examples/pokemon-service-lambda/src/main.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55

66
use std::sync::Arc;
77

8-
use aws_smithy_http_server::{routing::LambdaHandler, AddExtensionLayer};
8+
use aws_smithy_http_server::AddExtensionLayer;
99

1010
use pokemon_service_common::{
1111
capture_pokemon, check_health, do_nothing, get_pokemon_species, get_server_statistics,
1212
setup_tracing, stream_pokemon_radio, State,
1313
};
1414
use pokemon_service_lambda::get_storage_lambda;
15-
use pokemon_service_server_sdk::{PokemonService, PokemonServiceConfig};
15+
use pokemon_service_server_sdk::{
16+
server::routing::LambdaHandler, PokemonService, PokemonServiceConfig,
17+
};
1618

1719
#[tokio::main]
1820
pub async fn main() {

0 commit comments

Comments
 (0)