## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here -->
Because the build pipeline is checking for these.
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
## Motivation and Context
Extracted from #3308, this adds doc example scraping. This won't make
much of a difference yet but it will help if we're able to move example
repos directly under the SDKs themselves when appropriate.
## Description
https://doc.rust-lang.org/rustdoc/scraped-examples.html
## Testing
verified that examples appear in docs when expected
## Checklist
no changelog
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
---------
Co-authored-by: ysaito1001 <awsaito@amazon.com>
This PR fixes issues introduced by moving the repository from
awslabs/smithy-rs to smithy-lang/smithy-rs.
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
## Motivation and Context
Follow up on #3088
## Description
This PR reverts `ByteStream::read_with_body_0_4_from`,
`ByteStream::from_path_body_0_4`, and `ByteStream::from_file_body_0_4`
to the old names since from a customers' point of view, `FsBuilder`
should not mention anything about an `http-body` version at the API
level.
`FsBuilder` is currently an opt-in feature (with `rt-tokio` enabled) and
we make it tied to `http-body-0-4-x` by requiring `rt-tokio` including a
dependency on `http-body` version 0.4.x.
## Testing
Relied on the existing tests in CI
## Checklist
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
## Motivation and Context
Implements https://github.com/awslabs/smithy-rs/issues/3033
## Description
This PR hides behind cargo features the third-party types from
`http-body` and `hyper` crates that are used in`aws-smithy-types`'
public API. Customers need to opt-in by enabling a cargo feature
`http-body-0-4-x` in `aws-smithy-types` to create an `SdkBody` or
`ByteStream` using those third-party types. For more details, please see
[the upgrade
guide](https://github.com/awslabs/smithy-rs/discussions/3089).
As can been seen from code changes, to reduce the surface area where we
need to feature-gate things, we have fused the
`aws_smithy_types::body::Inner::Streaming` enum variant into
`aws_smithy_types::body::Inner::Dyn` variant, thereby removing
`SdkBody::from_dyn`.
## Testing
Relied on existing tests in CI
## Checklist
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
---------
Co-authored-by: Zelda Hessler <zhessler@amazon.com>
# Motivation and Context
A follow-up on #3026
## Description
#3026 moved
- `aws_smithy_http::body::{BoxBody, Error, SdkBody}` to
`aws_smithy_types::body::{BoxBody, Error, SdkBody}`
- `aws_smithy_http::byte_stream::{AggregatedBytes, ByteStream,
error::Error}` to `aws_smithy_types::byte_stream::{AggregatedBytes,
ByteStream, error::Error}`
and also left "breadcrumbs", so that customers could still consume
updated types from `aws_smithy_http` after the move.
This PR turns breadcrumbs into deprecation messages (via
`#[deprecated(...)]`) and updates existing places that used to use moved
types from `aws_smithy_http` to directly depend on `aws_smithy_types`.
## Testing
Relied on tests in CI.
## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
## Motivation and Context
Removes `futures_core::stream::Stream` from
`aws_smithy_http::byte_stream::ByteStream`
## Description
This PR is part of our ongoing effort,
https://github.com/awslabs/smithy-rs/issues/2413. We remove the
`futures_core::stream::Stream` trait from
`aws_smithy_http::byte_stream::ByteStream`. To continue support existing
places that relied upon `ByteStream` implementing the `Stream` trait, we
provide explicit `.next`, `.try_next`, and `.size_hints` methods on that
type. As part of it, a doc-hidden type `FuturesStreamCompatByteStream`,
which implements `Stream`, has been added to `aws_smithy_http` to cater
to those who need a type implementing `Stream` (see
[discussion](https://github.com/awslabs/smithy-rs/pull/2910#discussion_r1317112233)
why doc-hidden).
Another place we need to update is codegen responsible for rendering
stream payload serializer, and this affects the server. The regular
server and the python server have slightly different rendering
requirements, since the former uses
`aws_smithy_http::byte_stream::ByteStream` (that does _not_ implement
the `Stream` trait) and latter uses its own
[ByteStream](cb79a68e3c/rust-runtime/aws-smithy-http-server-python/src/types.rs (L343))
(that does implement `Stream`). We use
`ServerHttpBoundProtocolCustomization` to handle the difference:
`StreamPayloadSerializerCustomization` and
`PythonServerStreamPayloadSerializerCustomization`.
## Testing
No new behavior has been added, relied on the existing tests in CI.
## Checklist
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
## Motivation and Context
Python middleware were unable to change the URI which makes it
impossible to change the route of an incoming request in Python.
## Description
URI has a #[setter] that Python side can use to change it.
## Testing
- Test has been added that ensures URI can be changed from python.
- If the URI is modified by a middleware in a local smithy-rs Python
server, a different route will be invoked.
## Checklist
- I've updated the changelog.next.toml
Co-authored-by: Fahad Zubair <fahadzub@amazon.com>
## Motivation and Context
Allow Python users to configure their logging formatter to either
`json`, `pretty` or `compact` (default).
## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
Also, sort `Cargo.toml` dependencies if they were disordered.
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
This reverts commit 04db5e3572.
This is a breaking change that needs to wait to be merged in until the
next breaking release.
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
This patch also removes the unneeded dependency on `lambda_runtime` by
`aws-smithy-http-server-python`.
This patch also refactors `LambdaHandler`'s `convert_event` to avoid
cloning the URI path when not needed.
This is a breaking change. See #2676 why.
This patch also bumps `aws-smithy-http-server` dependency on `mime` to
0.3.4.
`cargo +nightly-2022-11-16 minimal-versions check --all-features`
otherwise
fails when using 0.3.0, because we require `impl fmt::Display for
mime::FromStrError`, which was first introduced in 0.3.4.
As to why `minimal-versions` is now picking `mime` 0.3.0 with this
patch, it's
because in `lambda_http` 0.7.3, they had [`mime =
"0.3.16"`](99dba64472/lambda-http/Cargo.toml (L35-L35)),
and in `lambda_http` 0.8.0, they've now relaxed that to [`mime =
"0.3"`](393d6447be/lambda-http/Cargo.toml (L36)).
## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
## Motivation and Context
This PR improves the Python stubs generation.
## Description
The main change is about avoiding to setup a placeholder for the Python
module and use the real module name, which allows to generate correct
docstrings during codegeneration.
We also change the stubs layout on disk, with the main stub entrypoint
called `__init__.pyi` instead of `$module_name.pyi`.
The README from the Rust runtime crate has been moved completely to the
example folder and I run autoformatting and style checks on the Python
example code.
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
---------
Signed-off-by: Bigo <1781140+crisidev@users.noreply.github.com>
Co-authored-by: Burak <unexge@gmail.com>
## Motivation and Context
We want to automatically generate stubs in the codegen diff to ensure
they can be reviewed and have a simple way to generate and include the
stubs inside the Maturin wheel.
## Description
The Python example has been moved to the `examples` folder and
refactored. The refactoring
ensures the script `stubgen.py` is included in the codegeneration of the
SDK crate. The script is later used to generate stubs automatically
during testing and can be used by customers to add their own stubs
before the Maturin build
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
----
_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
---------
Signed-off-by: Bigo <1781140+crisidev@users.noreply.github.com>
Co-authored-by: Burak <unexge@gmail.com>
* Add `RustType.Application` and `PythonType.Application` variants
* Use `RustType.Application` for event streaming symbols
* Call symbol provider to get `Receiver` type instead of hardcoding
* Add Python specific event streaming symbol provider
* Add event streaming wrapper generator
* Generate correct type information for event streaming types
* Add `CapturePokemon` operation to Python Pokemon service
* Add `InternalServerError` variant to all event streaming errors
* Use `PythonServerCargoDependency` for PyO3Asyncio imports
* Return an attribute error instead of panicking in `IntoPy` impls of wrappers
* Add `Sync` bound to `new` methods of wrappers
* Revert "Add `InternalServerError` variant to all event streaming errors"
This reverts commit b610cb27c7532102e3a3ec15a59da6c56b60c318.
* Add `PythonServerEventStreamErrorGenerator` to generate Python specific error types for unions
* Try to extract error type or inner type from incoming streaming value and ignore the value otherwise for now
* Allow missing type-stubs for `aiohttp`
* Propogate modelled errors through stream
* Raise modelled exceptions rather than sending through stream
* Allow senders from Python side to raise modelled exceptions
* Update `EventStreamSymbolProviderTest` to use `Application` type instead of `Opaque` type
* Fix `ktlint` issues
* Group up common variables in `codegenScope`
* Document `RustType.Application`
* Format `codegen-server-test/python/model/pokemon.smithy`
* Use `tokio-stream` crate instead of `futures` crate
* Use a better error message if user tries to reuse a stream
* Add some details about event streams to example Pokemon service
---------
Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com>
* Add initial implementation of unions with very broken symbol provider
* Add support for creating new unions in Python
* Generate getters and static methods for unions
* Allow to compile misc model
Signed-off-by: Bigo <1781140+crisidev@users.noreply.github.com>
* Doesn't work
* Now it works
* Simplify code a little
* Remove leftover from the many tries I did
* Finally fixed model generation with unions
* Fix wrong import
* Update to reflect changes in decorators
* Remove debugging output
* Simplify symbol provider
* Follow PR suggestions
* Remove union operation from python example
* Return `PyUnionMarker` for wrapped type in `IntoPy` impl
---------
Signed-off-by: Bigo <1781140+crisidev@users.noreply.github.com>
Co-authored-by: Burak Varlı <burakvar@amazon.co.uk>
* Remove `toEnumVariantName` from `RustSymbolProvider`
The `toEnumVariantName` function existed on symbol provider to work
around enum definitions not being shapes. In the future when we refactor
to use `EnumShape` instead of `EnumTrait`, there will be `MemberShape`s
for each enum member. This change incrementally moves us to that future
by creating fake `MemberShape`s in the enum generator from the enum
definition.
* Fix escaping of `Self` in symbol providers
* Clean up an old hack
* Make `RustReservedWordsSymbolProvider` configurable
* Update changelog
* Incorporate feedback
* Add `timestamp` type test and fix the conversion error
* Add some tests for `ByteStream` and fix async issues
* Use `__anext__` method instead of `anext`
---------
Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com>
* Upgrade Kotlin to 1.7.21
* Upgrade Ktlint to 0.48.2
* Run `pre-commit run --all-files` to fix broken Ktlints
* Fix string comparison broken by code formatting
* Initial Python stub generation
* Handle default values correctly
* Only generate `__init__` for classes that have constructor signatures
* Preserve doc comments
* Make context class generic
* Put type hint into a string to fix runtime error
* Run `mypy` on CI
* Use `make` to build Python SSDKs while generating diffs
* Escape Python types in Rust comments
* Only mark class methods with
* Sort imports to minimize diffs
* Add type annotations for `PySocket`
* Dont extend classes from `object` as every class already implicitly extended from `object`
* Use `vars` instead of `inspect.getmembers` to skip inherited members of a class
* Fix linting issues
* Add some tests for stubgen and refactor it
* Add type annotations to `PyMiddlewareException`
* Fix tests on Python 3.7
Python 3.7 doesn't support reading signatures from `__text_signature__`
for non-builtin functions (i.e. C/Rust functions). For testing we're using
regular Python syntax for defining signature.
* Provide default values for `typing.Optional[T]` types in type-stubs
* Update `is_fn_like` to cover more cases
* Remove `tools/smithy-rs-tool-common/`
* Make `DECORATORS` an array instead of a list
* Ignore missing type stub errors for `aiohttp`
* Add Python wrapper for `aws_smithy_types::Document`
* Remove unused type
* Make sure Python SSDKs uses Python specific `Document` type
* Allow Python specific `Document` type to be used in serialization and deserialization
* Make `pyo3/extension-module` a default feature
* Add `PythonServerTypesTest`
* Fix linting issues
In server SDKs, these traits can be implemented by any shape _except_ if
the shape's closure contains:
1. A `float`, `double`, or `document` shape: floating point types in
Rust do not implement `Eq`. Similarly, [`document` shapes] may
contain arbitrary JSON-like data containing floating point values.
2. A [@streaming] shape: all the streaming data would need to be
buffered first to compare it.
Additionally, the `Hash` trait cannot be implemented by shapes whose
closure contains:
1. A `map` shape: we render `map` shapes as `std::collections::HashMap`,
which _do not_ implement `Hash`. See
https://github.com/awslabs/smithy/issues/1567.
In **client SDKs, these traits cannot be derived on any code-generated
Rust types corresponding to Smithy shapes**, since e.g. adding new
optional members to a structure [is a backwards-compatible change], and
doing so alters the semantics of these traits.
However, this commit does implement these traits for the
`aws_smithy_types::date_time::DateTime` and `aws_smithy_types::Blob`
runtime types.
This change is necessary to efficiently implement the `@uniqueItems`
constraint trait in server SDKs.
[`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
[`Hash`]: https://doc.rust-lang.org/std/hash/trait.Hash.html
[`document` shapes]: https://smithy.io/2.0/spec/simple-types.html#document
[@streaming]: https://smithy.io/2.0/spec/streaming.html
[is a backwards-compatible change]: https://smithy.io/2.0/guides/evolving-models.html#updating-structures
This change creates `ClientCodegenDecorator` and
`ServerCodegenDecorator` in `codegen-client` and `codegen-server`
respectively to replace `RustCodegenDecorator`. Client/server
equivalents are created to replace `CombinedCodegenDecorator` as well.
This eliminates the need for the `supportsCodegenContext` method since
the decorator interface is no longer generic, so the `ServiceLoader` is
now powerful enough to differentiate.
The largest benefit, however, is that now clients and servers can have
separate customizations.
* Remove `lib` prefix from generated module names
* Build Pokemon service with `Maturin`
* Fix Maturin build on CI
* Generate minimal `pyproject.toml` for generated SDKs to build from source using Maturin
* Fix `ktlint` issues
* Bring back type stubs for Pokemon service
* Update instructions for Lambda
* Make `build-wheel` and `build-wheel-release` to depend on `codegen`
* Provide Python wrappers for Lambda related types
* Introduce `PyContext` to wrap raw context object
* Use new `PyContext` in handlers
* Expose `lambda` module to Python
* Use `LambdaContext` in example service
* Start Lambda handler in a different thread
* Print summary of Lambda context in Pokemon service
* Make sure to include Python `builtins` in tests
* Make `lambda_ctx` optional
Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com>
* Only inject types if they are type-hinted as `Optional[T]`
* Export Lambda module as `aws_lambda` instead of `lambda_`
* Comment why we need to run Hyper server in a background thread
* Move `is_optional_of` to `util` module
* Use `HeaderMap::from_iter` to build headers
* Support edge case of `(None, T)` in `util::is_optional_of`
* Make Lambda related types feature gated
* Remove feature gate for Lambda
* Make `xray_trace_id` an `Option`
* Remove `aws-lambda` feature from generated `Cargo.toml`s
* Fix linting issues
* Pin `lambda_runtime` to `0.7.1`
* Remove duplicate dependency in `Cargo.toml`
Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com>
* Add `PyTlsConfig` struct
* Support TLS server
* Add TLS support to Pokemon service
* Make sure to create `tokio::net::TcpListener` in a Tokio context
* Fix doc link
* Add missing imports in tests
* Add `tls::Listener`
* Reload TLS config periodically
* Add context to `TODO`
* Return `&'static str` from `base_url()`
* Flatten `match` in `tls::Listener`
* Propogate listener errors but ignore handshake errors in `tls::Listener`
* Add tests to `tls::Listener`
* Add test to `tls::Listener` to make sure we are propogating listener errors
* Use `PathBuf` instead of plain `String`s for paths
* 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.
* Python: map Python middlewares to Tower layers
* Make middleware layer infallible
* Use message and status code from `PyMiddlewareException`
* Introduce `FuncMetadata` to represent some information about a Python function
* Improve middleware errors
* Add missing copyright headers
* Allow accessing and changing request body
* Allow changing response
* Add some documentation about moving data back-and-forth between Rust and Python
* Add `mypy` to Pokemon service and update typings and comments for middlewares
* Add or update comments on the important types
* Add Rust equivalent of `collections.abc.MutableMapping`
* Add `PyHeaderMap` to make `HeaderMap` accessible from Python
* Apply suggestions from code review
Co-authored-by: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com>
* Improve logging
* Add `RichPyErr` to have a better output for `PyErr`s
* Better error messages for `PyMiddlewareError` variants
* Factor out repeating patterns in tests
* Preserve `__builtins__` in `globals` to fix tests in Python 3.7.10 (our CI version)
* Export `RichPyErr` to fix `cargo doc` error
* Apply suggestions from code review
Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com>
* Add missing SPDX headers
* Document that `keys`, `values` and `items` on `PyMutableMapping` causes clones
Co-authored-by: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com>
Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com>
* Avoid the chrono crate depending on the time crate
This commit is in response to RUSTSEC-2020-0071 where there is a
potential segfault in the time crate. The aws-smithy-types-convert
crate now disables the default features of the chrono crate so that
it will not depend on the time crate.
* Depend on lambda_http without RUSTSEC-2020-0071
This commit updates the version of lambda_http used by aws-smithy-http-server
and aws-smithy-http-server-python to 0.7.0. The prior version 0.6.0 of
lambda_http used the chrono crate in a way that exposed a security issue
described in RUSTSEC-2020-0071. By switching to 0.7.0 of lambda_http, those
two crates do not exhibit vulnerabilities as reported by cargo audit.
* Bump minor version of lambda_http in pokemon-service
This commit updates the version of `lambda_http` used by `pokemon-service`
from 0.6.0 to 0.7.0. This is in sync with the fact that both
`aws-smithy-http-server` and `aws-smithy-http-server-python` now depend
on 0.7.0 of `lambda_http`. Failing to do so would cause `pokemon-service`
to fail to compile due to an error at `lambda_http::run(handler)` in the
main function of the `pokemon-service-lambda` binary:
the trait `Service<lambda_http::http::Request<lambda_http::Body>>` is not
implemented for `LambdaHandler<aws_smithy_http_server::routing::Router>`
* Depend on lambda-http 0.7.1
This commit updates the version of `lambda_http` from 0.7.0 to 0.7.1 in
the crates within the top-level `rust-runtime` workspace. These updates
are needed to solve the issue described in awslabs/aws-lambda-rust-runtime#556
* Update CHANGELOG.next.toml
* Address https://github.com/awslabs/smithy-rs/pull/1907\#pullrequestreview-1161609833
Co-authored-by: Saito <awsaito@c889f3b5ddc4.ant.amazon.com>
Co-authored-by: Zelda Hessler <zhessler@amazon.com>
* Run clippy --fix for Rust 1.62.0 and format the resulting code
* Run clippy --fix on all targets
* Run clippy --fix with all features enabled
* Avoid extra allocation
* Use more idiomatic assert
* Ignore noisy lint
* Update pyo3 and pyo3-asyncio to 0.17.0
* Implement Eq on aws-smithy-checksums::Error
* Implement Eq on Protocol
* Replace conditionals with range-containment
* Implement Eq on types in aws-smithy-types
* Implement Eq on types in aws-smithy-http-server-python
* Implement Eq on types in aws-smithy-eventstream
* Implement Eq on types in aws-smithy-xml
* Implement Eq on aws-sigv4
* Update CI to use Rust 1.62.0
* Add Eq for generated types that implement PartialEq
* Allow clippy::needless_return in generated code
* Remove unnecessary reborrow in http_serde
* Remove unnecessary borrow in operation_deser
* Add CHANGELOG entries
* Revert "Add Eq for generated types that implement PartialEq"
This reverts commit 5169bd95aa.
* Update pyo3 and pyo3-asyncio in generated code for python server
* Allow clippy::derive_partial_eq_without_eq on structs and builders
* Run clippy on tools
* Fix accidental move in generated code
* Revert "Allow clippy::derive_partial_eq_without_eq on structs and builders"
This reverts commit 068c63ca20.
* Fix another accidental move in generated code
* Undo unwanted change to model
* Re-add reborrow in HttpBindingGenerator
* Fix clippy::format-push-string in changelogger
* Fix more uses of str.push_str(&format!(...))
* Remove unnecessary parenthesis
* Run ktlint
* Update aws/rust-runtime/aws-http/src/content_encoding.rs
Co-authored-by: John DiSanti <jdisanti@amazon.com>
* Update aws/rust-runtime/aws-http/src/content_encoding.rs
Co-authored-by: John DiSanti <jdisanti@amazon.com>
* Ignore doctest for non-exported macro
Rust 1.62 introduced a breaking change where doctests for non-exported
macros are now run by default. These don't compile because the macro
can't be imported in it.
See https://github.com/rust-lang/rust/issues/97030 for more info.
* Run cargo fmt
* Use $crate instead of crate in macro
* Revert "Implement Eq on types in aws-smithy-types"
This reverts commit c45a6b5a56.
* Revert "Implement Eq on types in aws-smithy-eventstream"
This reverts commit 78f4b07344.
* Revert "Implement Eq on types in aws-smithy-xml"
This reverts commit 590f01af73.
* Revert "Implement Eq on aws-sigv4"
This reverts commit d78bb62124.
* Revert "Implement Eq on types in aws-smithy-http-server-python"
This reverts commit f2cd901884.
* Revert "Implement Eq on aws-smithy-checksums::Error"
This reverts commit 5da170405e.
Co-authored-by: Julian Antonielli <julianantonielli@gmail.com>
Co-authored-by: John DiSanti <jdisanti@amazon.com>
* Allow running Python servers with Lambda handler
* Fix doctests
* Add `Running servers on AWS Lambda` section to docs
* Remove empty spaces from `README` to make linter happy
* Rename `run_lambda_server` to `run_lambda_handler`
* Add more comments to example `Dockerfile`
* Fix capitalization of logs
* Preserve original formatting of `PythonApplicationGenerator.kt`
* Replace AtomicU64 with AtomicUsize to prevent compilation issues on 32 bits platforms.
* Make sure that Rust tests compile on MacOS.
* Add CHANGELOG next entry.
* Simplify Python Pokemon service
* Use `threading.Lock` instead of `multiprocessing.Lock`
Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com>
* Explain why we need to pass `force=True`
* Add comment about synchronization of `Context` class
Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com>
## Motivation and Context
* Customers want to be able to implement simple middleware directly in Python. This PR aims to add the initial support for it.
* Improve the idiomatic experience of logging by exposing a handler compatible with Python's standard library `logging` module.
## Description
### Middleware
A middleware is defined as a sync or async Python function that can return multiple values, following these rules:
* Middleware not returning will let the execution continue without changing the original request.
* Middleware returning a modified Request will update the original request before continuing the execution.
* Middleware returning a Response will immediately terminate the request handling and return the response constructed from Python.
* Middleware raising MiddlewareException will immediately terminate the request handling and return a protocol specific error, with the option of setting the HTTP return code.
* Middleware raising any other exception will immediately terminate the request handling and return a protocol specific error, with HTTP status code 500.
Middlewares are registered into the Python application and executed in order of registration.
Example:
from sdk import App
from sdk.middleware import Request, MiddlewareException
app = App()
@app.request_middleware
def inject_header(request: Request):
request.set_header("x-amzn-answer", "42")
return request
@app.request_middleare
def check_header(request: Request):
if request.get_header("x-amzn-answer") != "42":
raise MiddlewareException("Wrong answer", 404)
@app.request_middleware
def dump_headers(request: Request):
logging.debug(f"Request headers after middlewares: {request.headers()}")
**NOTE: this PR only adds support for request middlewares, which are executed before the operation handler. Response middlewares, executed after the operation are tracked here: https://github.com/awslabs/smithy-rs/issues/1754.**
### Logging
To improve the idiomatic experience, now logging need to be configured from the Python side by using the standard `logging` module. This allows customers to opt-out of our `tracing` based logging implementation and use their own and logging level is now driven by Python.
import logging
from sdk.logging import TracingHandler
logging.basicConfig(level=logging.INFO, handlers=[TracingHandler.handle()])
Signed-off-by: Bigo <1781140+crisidev@users.noreply.github.com>
Co-authored-by: Burak <burakvar@amazon.co.uk>