Skip to content

Commit

Permalink
Add aws-lambda as a feature to generated server SDK (#3648)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
Co-authored-by: david-perez <[email protected]>
  • Loading branch information
3 people authored Jun 20, 2024
1 parent 6e0f418 commit 99e1e20
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
# message = "Fix typos in module documentation for generated crates"
# references = ["smithy-rs#920"]
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"
# author = "rcoh"
[[smithy-rs]]
message = "A feature, `aws-lambda`, has been added to generated SDKs to re-export types required for Lambda deployment."
references = ["smithy-rs#3643"]
meta = { "breaking" = false, "bug" = true, "tada" = false, "target" = "server" }
author = "drganjoo"
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class ServerRequiredCustomizations : ServerCodegenDecorator {
),
)

rustCrate.mergeFeature(
Feature(
"aws-lambda",
true,
listOf("aws-smithy-http-server/aws-lambda"),
),
)

rustCrate.withModule(ServerRustModule.Types) {
pubUseSmithyPrimitives(codegenContext, codegenContext.model, rustCrate)(this)
rustTemplate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class ServerRuntimeTypesReExportsGenerator(
}
pub mod request {
pub use #{SmithyHttpServer}::request::FromParts;
##[cfg(feature = "aws-lambda")]
pub mod lambda {
pub use #{SmithyHttpServer}::request::lambda::Context;
}
}
pub mod response {
pub use #{SmithyHttpServer}::response::IntoResponse;
Expand Down
4 changes: 2 additions & 2 deletions examples/pokemon-service-lambda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ tracing = "0.1"
lambda_http = "0.8.0"

# Local paths
aws-smithy-http-server = { path = "../../rust-runtime/aws-smithy-http-server", features = ["aws-lambda"] }
pokemon-service-server-sdk = { path = "../pokemon-service-server-sdk/" }
aws-smithy-http-server = { path = "../../rust-runtime/aws-smithy-http-server" }
pokemon-service-server-sdk = { path = "../pokemon-service-server-sdk/", features = ["aws-lambda"] }
pokemon-service-common = { path = "../pokemon-service-common/" }
3 changes: 2 additions & 1 deletion examples/pokemon-service-lambda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

use std::sync::Arc;

use aws_smithy_http_server::{request::lambda::Context, Extension};
use aws_smithy_http_server::Extension;

use pokemon_service_common::State;
use pokemon_service_server_sdk::{
error::{GetStorageError, StorageAccessNotAuthorized},
input::GetStorageInput,
output::GetStorageOutput,
server::request::lambda::Context,
};

/// Retrieves the user's storage and logs the lambda request ID.
Expand Down
6 changes: 4 additions & 2 deletions examples/pokemon-service-lambda/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

use std::sync::Arc;

use aws_smithy_http_server::{routing::LambdaHandler, AddExtensionLayer};
use aws_smithy_http_server::AddExtensionLayer;

use pokemon_service_common::{
capture_pokemon, check_health, do_nothing, get_pokemon_species, get_server_statistics,
setup_tracing, stream_pokemon_radio, State,
};
use pokemon_service_lambda::get_storage_lambda;
use pokemon_service_server_sdk::{PokemonService, PokemonServiceConfig};
use pokemon_service_server_sdk::{
server::routing::LambdaHandler, PokemonService, PokemonServiceConfig,
};

#[tokio::main]
pub async fn main() {
Expand Down

0 comments on commit 99e1e20

Please sign in to comment.