Unverified Commit 3a9a42bb authored by Luca Palmieri's avatar Luca Palmieri Committed by GitHub
Browse files

Introduce an `aws-lambda` feature. (#2035)

* Introduce an `aws-lambda` feature.

* Add CHANGELOG

* Use the new and shiny feature syntax to avoid creating an implicit `lambda_http` feature.

* Add `aws-lambda` feature to the Python server. Enable the `aws-lambda` feature in our example. Be explicit in providing an implementation of request rejection for Box<dyn Error>.

* Add an `aws-lambda` feature flag to the generated Python-specific crate. We enable it by default to make sure the Lambda method ends up visible in the final Python wrapper library.
parent 0adad6a7
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -487,3 +487,15 @@ message = "Make generated enum `values()` functions callable in const contexts."
references = ["smithy-rs#2011"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all" }
author = "lsr0"

[[smithy-rs]]
message = """
All types that are exclusively relevant within the context of an AWS Lambda function are now gated behind the
`aws-lambda` feature flag.

This will reduce the number of dependencies (and improve build times) for users that are running their Smithy services
in non-serverless environments (e.g. via `hyper`).
"""
references = ["smithy-rs#2035"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" }
author = "LukeMathWalker"
+18 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.customizations

import software.amazon.smithy.model.neighbor.Walker
import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.core.rustlang.Feature
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.docs
import software.amazon.smithy.rust.codegen.core.rustlang.rust
@@ -103,6 +104,21 @@ class PubUsePythonTypesDecorator : RustCodegenDecorator<ServerProtocolGenerator,
        clazz.isAssignableFrom(ServerCodegenContext::class.java)
}

/**
 * Decorator adding an `aws-lambda` feature to the generated crate.
 */
class PythonFeatureFlagsDecorator : RustCodegenDecorator<ServerProtocolGenerator, ServerCodegenContext> {
    override val name: String = "PythonFeatureFlagsDecorator"
    override val order: Byte = 0

    override fun extras(codegenContext: ServerCodegenContext, rustCrate: RustCrate) {
        rustCrate.mergeFeature(Feature("aws-lambda", true, listOf("aws-smithy-http-server-python/aws-lambda")))
    }

    override fun supportsCodegenContext(clazz: Class<out CodegenContext>): Boolean =
        clazz.isAssignableFrom(ServerCodegenContext::class.java)
}

val DECORATORS = listOf(
    /**
     * Add the [InternalServerError] error to all operations.
@@ -115,4 +131,6 @@ val DECORATORS = listOf(
    PubUsePythonTypesDecorator(),
    // Render the Python shared library export.
    PythonExportModuleDecorator(),
    // Add the `aws-lambda` feature flag
    PythonFeatureFlagsDecorator(),
)
+1 −0
Original line number Diff line number Diff line
@@ -278,6 +278,7 @@ class PythonApplicationGenerator(
                    self.run_server(py, address, port, backlog, workers)
                }
                /// Lambda entrypoint: start the server on Lambda.
                ##[cfg(feature = "aws-lambda")]
                ##[pyo3(text_signature = "(${'$'}self)")]
                pub fn run_lambda(
                    &mut self,
+4 −1
Original line number Diff line number Diff line
@@ -12,6 +12,9 @@ Python server runtime for Smithy Rust Server Framework.
"""
publish = true

[features]
aws-lambda = ["aws-smithy-http-server/aws-lambda", "dep:lambda_http"]

[dependencies]
aws-smithy-http = { path = "../aws-smithy-http" }
aws-smithy-http-server = { path = "../aws-smithy-http-server" }
@@ -22,7 +25,7 @@ bytes = "1.2"
futures = "0.3"
http = "0.2"
hyper = { version = "0.14.20", features = ["server", "http1", "http2", "tcp", "stream"] }
lambda_http = "0.7.1"
lambda_http = { version = "0.7.1", optional = true }
num_cpus = "1.13.1"
parking_lot = "0.12.1"
pin-project-lite = "0.2"
+2 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#![cfg_attr(docsrs, feature(doc_cfg))]

//! Rust/Python bindings, runtime and utilities.
//!
//! This crates implements all the generic code needed to start and manage
Loading