awslabs / aws-sdk-rust

AWS SDK for the Rust Programming Language
https://awslabs.github.io/aws-sdk-rust/
Apache License 2.0
3.04k stars 247 forks source link

https_proxy support #169

Open matiu2 opened 3 years ago

matiu2 commented 3 years ago

Bug Report

Though the readme says that you can set the environment variables: http_proxy, https_proxy, HTTP_PROXY, HTTPS_PROXY and the SDK will use them, it completely ignores them.

Version

my-cli2 v0.1.0 (/Users/sherbomd/projects/my-cli2)
├── anyhow v1.0.42
├── aws-auth v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   ├── smithy-http v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   │   ├── bytes v1.0.1
│   │   ├── bytes-utils v0.1.1
│   │   │   ├── bytes v1.0.1
│   │   │   └── either v1.6.1
│   │   ├── futures-core v0.3.16
│   │   ├── http v0.2.4
│   │   │   ├── bytes v1.0.1
│   │   │   ├── fnv v1.0.7
│   │   │   └── itoa v0.4.7
│   │   ├── http-body v0.4.2
│   │   │   ├── bytes v1.0.1
│   │   │   ├── http v0.2.4 (*)
│   │   │   └── pin-project-lite v0.2.7
│   │   ├── hyper v0.14.11
│   │   │   ├── bytes v1.0.1
│   │   │   ├── futures-channel v0.3.16
│   │   │   │   └── futures-core v0.3.16
│   │   │   ├── futures-core v0.3.16
│   │   │   ├── futures-util v0.3.16
│   │   │   │   ├── futures-core v0.3.16
│   │   │   │   ├── futures-macro v0.3.16 (proc-macro)
│   │   │   │   │   ├── proc-macro-hack v0.5.19 (proc-macro)
│   │   │   │   │   ├── proc-macro2 v1.0.28
│   │   │   │   │   │   └── unicode-xid v0.2.2
│   │   │   │   │   ├── quote v1.0.9
│   │   │   │   │   │   └── proc-macro2 v1.0.28 (*)
│   │   │   │   │   └── syn v1.0.74
│   │   │   │   │       ├── proc-macro2 v1.0.28 (*)
│   │   │   │   │       ├── quote v1.0.9 (*)
│   │   │   │   │       └── unicode-xid v0.2.2
│   │   │   │   │   [build-dependencies]
│   │   │   │   │   └── autocfg v1.0.1
│   │   │   │   ├── futures-task v0.3.16
│   │   │   │   ├── pin-project-lite v0.2.7
│   │   │   │   ├── pin-utils v0.1.0
│   │   │   │   ├── proc-macro-hack v0.5.19 (proc-macro)
│   │   │   │   ├── proc-macro-nested v0.1.7
│   │   │   │   └── slab v0.4.3
│   │   │   │   [build-dependencies]
│   │   │   │   └── autocfg v1.0.1
│   │   │   ├── h2 v0.3.3
│   │   │   │   ├── bytes v1.0.1
│   │   │   │   ├── fnv v1.0.7
│   │   │   │   ├── futures-core v0.3.16
│   │   │   │   ├── futures-sink v0.3.16
│   │   │   │   ├── futures-util v0.3.16 (*)
│   │   │   │   ├── http v0.2.4 (*)
│   │   │   │   ├── indexmap v1.7.0
│   │   │   │   │   └── hashbrown v0.11.2
│   │   │   │   │   [build-dependencies]
│   │   │   │   │   └── autocfg v1.0.1
│   │   │   │   ├── slab v0.4.3
│   │   │   │   ├── tokio v1.9.0
│   │   │   │   │   ├── bytes v1.0.1
│   │   │   │   │   ├── libc v0.2.98
│   │   │   │   │   ├── memchr v2.4.0
│   │   │   │   │   ├── mio v0.7.13
│   │   │   │   │   │   ├── libc v0.2.98
│   │   │   │   │   │   └── log v0.4.14
│   │   │   │   │   │       └── cfg-if v1.0.0
│   │   │   │   │   ├── num_cpus v1.13.0
│   │   │   │   │   │   └── libc v0.2.98
│   │   │   │   │   ├── once_cell v1.8.0
│   │   │   │   │   ├── parking_lot v0.11.1
│   │   │   │   │   │   ├── instant v0.1.10
│   │   │   │   │   │   │   └── cfg-if v1.0.0
│   │   │   │   │   │   ├── lock_api v0.4.4
│   │   │   │   │   │   │   └── scopeguard v1.1.0
│   │   │   │   │   │   └── parking_lot_core v0.8.3
│   │   │   │   │   │       ├── cfg-if v1.0.0
│   │   │   │   │   │       ├── instant v0.1.10 (*)
│   │   │   │   │   │       ├── libc v0.2.98
│   │   │   │   │   │       └── smallvec v1.6.1
│   │   │   │   │   ├── pin-project-lite v0.2.7
│   │   │   │   │   ├── signal-hook-registry v1.4.0
│   │   │   │   │   │   └── libc v0.2.98
│   │   │   │   │   └── tokio-macros v1.3.0 (proc-macro)
│   │   │   │   │       ├── proc-macro2 v1.0.28 (*)
│   │   │   │   │       ├── quote v1.0.9 (*)
│   │   │   │   │       └── syn v1.0.74 (*)
│   │   │   │   │   [build-dependencies]
│   │   │   │   │   └── autocfg v1.0.1
│   │   │   │   ├── tokio-util v0.6.7
│   │   │   │   │   ├── bytes v1.0.1
│   │   │   │   │   ├── futures-core v0.3.16
│   │   │   │   │   ├── futures-sink v0.3.16
│   │   │   │   │   ├── log v0.4.14 (*)
│   │   │   │   │   ├── pin-project-lite v0.2.7
│   │   │   │   │   └── tokio v1.9.0 (*)
│   │   │   │   └── tracing v0.1.26
│   │   │   │       ├── cfg-if v1.0.0
│   │   │   │       ├── log v0.4.14 (*)
│   │   │   │       ├── pin-project-lite v0.2.7
│   │   │   │       ├── tracing-attributes v0.1.15 (proc-macro)
│   │   │   │       │   ├── proc-macro2 v1.0.28 (*)
│   │   │   │       │   ├── quote v1.0.9 (*)
│   │   │   │       │   └── syn v1.0.74 (*)
│   │   │   │       └── tracing-core v0.1.18
│   │   │   │           └── lazy_static v1.4.0
│   │   │   ├── http v0.2.4 (*)
│   │   │   ├── http-body v0.4.2 (*)
│   │   │   ├── httparse v1.4.1
│   │   │   ├── httpdate v1.0.1
│   │   │   ├── itoa v0.4.7
│   │   │   ├── pin-project-lite v0.2.7
│   │   │   ├── socket2 v0.4.0
│   │   │   │   └── libc v0.2.98
│   │   │   ├── tokio v1.9.0 (*)
│   │   │   ├── tower-service v0.3.1
│   │   │   ├── tracing v0.1.26 (*)
│   │   │   └── want v0.3.0
│   │   │       ├── log v0.4.14 (*)
│   │   │       └── try-lock v0.2.3
│   │   ├── percent-encoding v2.1.0
│   │   ├── pin-project v1.0.8
│   │   │   └── pin-project-internal v1.0.8 (proc-macro)
│   │   │       ├── proc-macro2 v1.0.28 (*)
│   │   │       ├── quote v1.0.9 (*)
│   │   │       └── syn v1.0.74 (*)
│   │   ├── smithy-types v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   │   │   └── chrono v0.4.19
│   │   │       ├── libc v0.2.98
│   │   │       ├── num-integer v0.1.44
│   │   │       │   └── num-traits v0.2.14
│   │   │       │       [build-dependencies]
│   │   │       │       └── autocfg v1.0.1
│   │   │       │   [build-dependencies]
│   │   │       │   └── autocfg v1.0.1
│   │   │       └── num-traits v0.2.14 (*)
│   │   ├── thiserror v1.0.26
│   │   │   └── thiserror-impl v1.0.26 (proc-macro)
│   │   │       ├── proc-macro2 v1.0.28 (*)
│   │   │       ├── quote v1.0.9 (*)
│   │   │       └── syn v1.0.74 (*)
│   │   ├── tokio v1.9.0 (*)
│   │   ├── tokio-util v0.6.7 (*)
│   │   └── tracing v0.1.26 (*)
│   └── zeroize v1.4.1
├── aws-endpoint v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   ├── aws-types v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   │   └── lazy_static v1.4.0
│   │   [build-dependencies]
│   │   └── rustc_version v0.3.3
│   │       └── semver v0.11.0
│   │           └── semver-parser v0.10.2
│   │               └── pest v2.1.3
│   │                   └── ucd-trie v0.1.3
│   ├── http v0.2.4 (*)
│   ├── regex v1.5.4
│   │   ├── aho-corasick v0.7.18
│   │   │   └── memchr v2.4.0
│   │   ├── memchr v2.4.0
│   │   └── regex-syntax v0.6.25
│   └── smithy-http v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
├── aws-sdk-sts v0.0.12-alpha (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   ├── aws-auth v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   ├── aws-endpoint v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   ├── aws-http v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   │   ├── aws-types v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   ├── http v0.2.4 (*)
│   │   ├── lazy_static v1.4.0
│   │   ├── smithy-http v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   ├── smithy-types v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   └── thiserror v1.0.26 (*)
│   ├── aws-hyper v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   │   ├── aws-auth v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   ├── aws-endpoint v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   ├── aws-http v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   ├── aws-sig-auth v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   │   │   ├── aws-auth v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   │   ├── aws-sigv4 v0.1.0 (https://github.com/rcoh/sigv4?rev=66b1646a7ab119c73be966ca70ee5f556bd8379b#66b1646a)
│   │   │   │   ├── bytes v1.0.1
│   │   │   │   ├── chrono v0.4.19 (*)
│   │   │   │   ├── hex v0.4.3
│   │   │   │   ├── http v0.2.4 (*)
│   │   │   │   ├── http-body v0.4.2 (*)
│   │   │   │   ├── percent-encoding v2.1.0
│   │   │   │   ├── ring v0.16.20
│   │   │   │   │   ├── spin v0.5.2
│   │   │   │   │   └── untrusted v0.7.1
│   │   │   │   │   [build-dependencies]
│   │   │   │   │   └── cc v1.0.69
│   │   │   │   ├── serde v1.0.126
│   │   │   │   │   └── serde_derive v1.0.126 (proc-macro)
│   │   │   │   │       ├── proc-macro2 v1.0.28 (*)
│   │   │   │   │       ├── quote v1.0.9 (*)
│   │   │   │   │       └── syn v1.0.74 (*)
│   │   │   │   └── serde_urlencoded v0.7.0
│   │   │   │       ├── form_urlencoded v1.0.1
│   │   │   │       │   ├── matches v0.1.8
│   │   │   │       │   └── percent-encoding v2.1.0
│   │   │   │       ├── itoa v0.4.7
│   │   │   │       ├── ryu v1.0.5
│   │   │   │       └── serde v1.0.126 (*)
│   │   │   ├── aws-types v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   │   ├── http v0.2.4 (*)
│   │   │   ├── smithy-http v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   │   └── thiserror v1.0.26 (*)
│   │   ├── bytes v1.0.1
│   │   ├── fastrand v1.5.0
│   │   ├── http v0.2.4 (*)
│   │   ├── http-body v0.4.2 (*)
│   │   ├── hyper v0.14.11 (*)
│   │   ├── hyper-rustls v0.22.1
│   │   │   ├── ct-logs v0.8.0
│   │   │   │   └── sct v0.6.1
│   │   │   │       ├── ring v0.16.20 (*)
│   │   │   │       └── untrusted v0.7.1
│   │   │   ├── futures-util v0.3.16 (*)
│   │   │   ├── hyper v0.14.11 (*)
│   │   │   ├── log v0.4.14 (*)
│   │   │   ├── rustls v0.19.1
│   │   │   │   ├── base64 v0.13.0
│   │   │   │   ├── log v0.4.14 (*)
│   │   │   │   ├── ring v0.16.20 (*)
│   │   │   │   ├── sct v0.6.1 (*)
│   │   │   │   └── webpki v0.21.4
│   │   │   │       ├── ring v0.16.20 (*)
│   │   │   │       └── untrusted v0.7.1
│   │   │   ├── rustls-native-certs v0.5.0
│   │   │   │   ├── rustls v0.19.1 (*)
│   │   │   │   └── security-framework v2.3.1
│   │   │   │       ├── bitflags v1.2.1
│   │   │   │       ├── core-foundation v0.9.1
│   │   │   │       │   ├── core-foundation-sys v0.8.2
│   │   │   │       │   └── libc v0.2.98
│   │   │   │       ├── core-foundation-sys v0.8.2
│   │   │   │       ├── libc v0.2.98
│   │   │   │       └── security-framework-sys v2.3.0
│   │   │   │           ├── core-foundation-sys v0.8.2
│   │   │   │           └── libc v0.2.98
│   │   │   ├── tokio v1.9.0 (*)
│   │   │   ├── tokio-rustls v0.22.0
│   │   │   │   ├── rustls v0.19.1 (*)
│   │   │   │   ├── tokio v1.9.0 (*)
│   │   │   │   └── webpki v0.21.4 (*)
│   │   │   └── webpki v0.21.4 (*)
│   │   ├── pin-project v1.0.8 (*)
│   │   ├── protocol-test-helpers v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   │   │   ├── assert-json-diff v1.1.0
│   │   │   │   ├── extend v0.1.2 (proc-macro)
│   │   │   │   │   ├── proc-macro-error v1.0.4
│   │   │   │   │   │   ├── proc-macro-error-attr v1.0.4 (proc-macro)
│   │   │   │   │   │   │   ├── proc-macro2 v1.0.28 (*)
│   │   │   │   │   │   │   └── quote v1.0.9 (*)
│   │   │   │   │   │   │   [build-dependencies]
│   │   │   │   │   │   │   └── version_check v0.9.3
│   │   │   │   │   │   ├── proc-macro2 v1.0.28 (*)
│   │   │   │   │   │   ├── quote v1.0.9 (*)
│   │   │   │   │   │   └── syn v1.0.74 (*)
│   │   │   │   │   │   [build-dependencies]
│   │   │   │   │   │   └── version_check v0.9.3
│   │   │   │   │   ├── proc-macro2 v1.0.28 (*)
│   │   │   │   │   ├── quote v1.0.9 (*)
│   │   │   │   │   └── syn v1.0.74 (*)
│   │   │   │   ├── serde v1.0.126 (*)
│   │   │   │   └── serde_json v1.0.64
│   │   │   │       ├── itoa v0.4.7
│   │   │   │       ├── ryu v1.0.5
│   │   │   │       └── serde v1.0.126 (*)
│   │   │   ├── http v0.2.4 (*)
│   │   │   ├── pretty_assertions v0.7.2
│   │   │   │   ├── ansi_term v0.12.1
│   │   │   │   └── diff v0.1.12
│   │   │   ├── regex v1.5.4 (*)
│   │   │   ├── roxmltree v0.14.1
│   │   │   │   └── xmlparser v0.13.3
│   │   │   ├── serde_json v1.0.64 (*)
│   │   │   └── thiserror v1.0.26 (*)
│   │   ├── smithy-client v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   │   │   ├── bytes v1.0.1
│   │   │   ├── fastrand v1.5.0
│   │   │   ├── http v0.2.4 (*)
│   │   │   ├── http-body v0.4.2 (*)
│   │   │   ├── hyper v0.14.11 (*)
│   │   │   ├── hyper-rustls v0.22.1 (*)
│   │   │   ├── pin-project v1.0.8 (*)
│   │   │   ├── protocol-test-helpers v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   │   ├── smithy-http v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   │   ├── smithy-http-tower v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   │   │   │   ├── bytes v1.0.1
│   │   │   │   ├── http v0.2.4 (*)
│   │   │   │   ├── http-body v0.4.2 (*)
│   │   │   │   ├── pin-project v1.0.8 (*)
│   │   │   │   ├── smithy-http v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   │   │   ├── tower v0.4.8
│   │   │   │   │   ├── futures-core v0.3.16
│   │   │   │   │   ├── futures-util v0.3.16 (*)
│   │   │   │   │   ├── pin-project v1.0.8 (*)
│   │   │   │   │   ├── tokio v1.9.0 (*)
│   │   │   │   │   ├── tower-layer v0.3.1
│   │   │   │   │   ├── tower-service v0.3.1
│   │   │   │   │   └── tracing v0.1.26 (*)
│   │   │   │   └── tracing v0.1.26 (*)
│   │   │   ├── smithy-types v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   │   ├── tokio v1.9.0 (*)
│   │   │   ├── tower v0.4.8 (*)
│   │   │   └── tracing v0.1.26 (*)
│   │   ├── smithy-http v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   ├── smithy-http-tower v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   ├── smithy-types v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   ├── tokio v1.9.0 (*)
│   │   ├── tower v0.4.8 (*)
│   │   └── tracing v0.1.26 (*)
│   ├── aws-sig-auth v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   ├── aws-types v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   ├── bytes v1.0.1
│   ├── http v0.2.4 (*)
│   ├── smithy-http v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   ├── smithy-query v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│   │   ├── itoa v0.4.7
│   │   ├── ryu v1.0.5
│   │   ├── smithy-types v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   │   └── urlencoding v1.3.3
│   ├── smithy-types v0.0.1 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
│   └── smithy-xml v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957)
│       ├── thiserror v1.0.26 (*)
│       └── xmlparser v0.13.3
├── aws-types v0.1.0 (https://github.com/awslabs/aws-sdk-rust?tag=v0.0.12-alpha#d61aa957) (*)
├── dotenv v0.15.0
├── http v0.2.4 (*)
├── log v0.4.14 (*)
├── pretty_env_logger v0.4.0
│   ├── env_logger v0.7.1
│   │   ├── atty v0.2.14
│   │   │   └── libc v0.2.98
│   │   ├── humantime v1.3.0
│   │   │   └── quick-error v1.2.3
│   │   ├── log v0.4.14 (*)
│   │   ├── regex v1.5.4 (*)
│   │   └── termcolor v1.1.2
│   └── log v0.4.14 (*)
└── tokio v1.9.0 (*)

Platform

Darwin C02FV07DMD6R 19.6.0 Darwin Kernel Version 19.6.0: Tue Jun 22 19:49:55 PDT 2021; root:xnu-6153.141.35~1/RELEASE_X86_64 x86_64

AWS Services

STS

Description

When providing https_proxy et. al environment variables, I expect it to use them, but it tries to connect directly instead:

$ https_proxy=http://localhost:3128 http_proxy=http://localhost:3128 HTTPS_PROXY=http://localhost:3128 HTTP_PROXY=http://localhost:3128 RUST_LOG=debug cargo run
  ...
 INFO  cba_cli2 > Getting token
 INFO  smithy_http_tower::parse_response > send_operation
 INFO  smithy_http_tower::parse_response > send_operation; operation="GetSessionToken"
 INFO  smithy_http_tower::parse_response > send_operation; service="sts"
 DEBUG hyper::client::connect::dns       > resolving host="sts.ap-southeast-2.amazonaws.com"
 DEBUG hyper::client::connect::http      > connecting to 99.82.187.15:443
 ... timeout ...

instead, it tries to connect directly.

I used this code (Just trying to get an sts session_token):

let creds = Credentials::from_keys(access_key, secret_key, None);
let region = Region::from_static("ap-southeast-2");
let config = Config::builder()
    .credentials_provider(creds)
    //.endpoint_resolver(endpoint)
    .region(&region)
    .build();
let client = Client::from_conf(config);
let serial_number = format!("arn:aws:iam::{}:mfa/{}", account_number, user);
log::info!("Getting token");
let token = client
    .get_session_token()
    .set_serial_number(Some(serial_number))
    .set_token_code(Some(mfa_token))
    .set_duration_seconds(Some(43_200))
    .send()
    .await;
log::info!("Token: {:?}", token);

When running with (the http_proxy et. al are already in the env):

RUST_LOG='smithy_http_tower::dispatch=trace,smithy_http::middleware=trace' cargo run

I get:

TRACE smithy_http_tower::dispatch > request=Request { method: POST, uri: https://sts.ap-southeast-2.amazonaws.com/, version: HTTP/1.1, headers: {"content-type": "application/x-www-form-urlencoded", "content-length": "139", "host": "sts.ap-southeast-2.amazonaws.com", "user-agent": "aws-sdk-rust/0.1.0 os/macos lang/rust/1.53.0", "x-amz-user-agent": "aws-sdk-rust/0.1.0 api/sts/0.0.12-alpha os/macos lang/rust/1.53.0", "authorization": Sensitive, "x-amz-date": "20210728T115347Z"}, body: SdkBody { inner: Once(Some(b"Action=GetSessionToken&Version=2011-06-15&DurationSeconds=43200&SerialNumber=arn%3Aaws%3Aiam%3A%3XXXXXXX%3Amfa%2FXXXXXX&TokenCode=a")), retryable: true } }
rcoh commented 3 years ago

that's correct, out of the box the SDK does not support HTTP proxy. which README are you referring to? Would be good to correct that. It's possible to replace Hyper with with Reqwest in the SDK to gain HTTP proxy support, although it requires a bit of code.

matiu2 commented 3 years ago

I was referring to the main project readme - but it looks like you already fixed it :)

I'm behind a corporate proxy. What's the best way forward for me to continue using aws-sdk ?

Any direction appreciated.

benesch commented 3 years ago

I'm not spun up on the AWS SDK yet, but if it allows replacing the transport, we (@MaterializeInc) recently wrote some code to teach hyper to respect http_proxy and friends: https://dev.materialize.com/api/rust/http_util/index.html. You can see the code here: https://github.com/MaterializeInc/materialize/blob/main/src/http-util/src/hyper.rs

It's not open source right now, but let me see what I can do about that. It's based on the hyper_proxy crate, which is usable on its own, but our little shim does the work of looking at http_proxy, https_proxy, and no_proxy and configuring hyper_proxy correctly.

matiu2 commented 3 years ago

Goal: Create a smithy_client that I can use with sts, but with a hyper_proxy::Connector.

I'm trying to get access to the underlying hyper client, but so far without success. So far I have this:

//! Handles everything to do with reading the https_proxy environment variable
use hyper::client::HttpConnector;
use hyper::Client;
use hyper_proxy::{Intercept, Proxy, ProxyConnector};
use smithy_client::Builder;
use smithy_http::operation::BuildError;
use std::env;

/// Returns a proxy if the https_proxy environment varablie is set
pub fn proxy() -> anyhow::Result<Option<ProxyConnector<HttpConnector>>> {
    // TODO: Convert errors to thiserror
    let https_proxy = env::var("https_proxy")?;
    if https_proxy.is_empty() {
        Ok(None)
    } else {
        let proxy = {
            let proxy_uri = https_proxy.parse()?;
            let proxy = Proxy::new(Intercept::All, proxy_uri);
            let connector = HttpConnector::new();
            let proxy_connector = ProxyConnector::from_proxy(connector, proxy)?;
            proxy_connector
        };
        Ok(Some(proxy))
    }
}

/// If the https_proxy environment variable is set, returns a DynConnector you can use with other AWS services
/// Otherwise, returns nothing, so you can just use the aws-sdk-rust library normally
pub fn connector() -> anyhow::Result<Option<smithy_client::Client>> {
    Ok(proxy()?
        // Turn the proxy into a hyper::Client
        .map(|proxy| Client::builder().build(proxy))
        // Turn the hyper client into a DynConnector (it used to be like that, but then I changed it. Neither work so far).
        .map(|client| Builder::hyper(client).build()))
}

// .. and later...
    let proxy_conn = connector().unwrap().unwrap();
    let client = Client::from_conf_conn(config, proxy_conn);
    log::info!("Getting token");
    let token = client
        // It dies here..
        .get_session_token()

Error message:

error[E0599]: the method `get_session_token` exists for struct `aws_sdk_sts::Client<smithy_client::Client>`, but its trait bounds were not satisfied
   --> src/main.rs:40:10
    |
40  |           .get_session_token()
    |            ^^^^^^^^^^^^^^^^^ method cannot be called on `aws_sdk_sts::Client<smithy_client::Client>` due to unsatisfied trait bounds
    |
   ::: /Users/sherbomd/.cargo/git/checkouts/aws-sdk-rust-be00ef1d3f696844/d61aa95/sdk/smithy-client/src/lib.rs:92:1
    |
92  | / pub struct Client<
93  | |     Connector = erase::DynConnector,
94  | |     Middleware = erase::DynMiddleware<Connector>,
95  | |     RetryPolicy = retry::Standard,
...   |
99  | |     retry_policy: RetryPolicy,
100 | | }
    | |_- doesn't satisfy `smithy_client::Client: SmithyConnector`
    |
    = note: the following trait bounds were not satisfied:
            `smithy_client::Client: SmithyConnector`

I'm working on this in my little spare. I'll probably get there eventually, but any direction from devs would help.

rcoh commented 3 years ago

I suspect the error is that the response body type hasn't been converted. You can use HyperAdapter from smithy-client to wrap your new hyper client in the same way we wrap the base one. Also, I can't remember exactly why, but when I did this a few months ago, hyper_proxy wasn't working and I ended up wrapping reqwest instead. Might have been my specific use case though. In any case, this compiles although I haven't tested it. The key is wrapping your client in HyperAdapter:

use hyper::client::HttpConnector;
use hyper::Client;
use hyper_proxy::{Intercept, Proxy, ProxyConnector};
use smithy_client::bounds::SmithyConnector;
//use smithy_http::body::SdkBody;
//use tower::{BoxError, Service};

fn main() {
    let proxy = {
        let proxy_uri = "http://my-proxy:8080".parse().unwrap();
        let proxy = Proxy::new(Intercept::All, proxy_uri);
        //proxy.set_authorization(Authorization::basic("John Doe", "Agent1234"));
        let connector = HttpConnector::new();
        let proxy_connector = ProxyConnector::from_proxy(connector, proxy).unwrap();
        proxy_connector
    };
    let hyper_client = Client::builder().build(proxy);
    // need to ensure the `hyper` feature of smithy-client is enabled
    let hyper_client = smithy_client::hyper_ext::Adapter::from(hyper_client);
    let hyper_client = check_bounds(hyper_client);
    let conf = aws_sdk_sts::Config::builder().build();
    let sts = aws_sdk_sts::Client::from_conf_conn(conf, hyper_client);
    sts.get_session_token().send();
}
matiu2 commented 3 years ago

That got me going. Thank you :) @rcoh

I'd like to leave this open though.

Feature request:

This would be consistent with the other (python for example) sdks (I think).

ghost commented 2 years ago

The above example didn't work for me, had to change it a bit:

hyper-tls = "0.5.0"
hyper-proxy = "0.9.1"
hyper = "0.14.16"

aws-smithy-client = { version = "0.34.1", features = ["hyper"] }
let proxy = {
        let proxy_uri = "http://my-proxy:8080".parse().unwrap();
        let proxy = Proxy::new(Intercept::All, proxy_uri);
        //proxy.set_authorization(Authorization::basic("John Doe", "Agent1234"));
        let connector = HttpConnector::new();
        let proxy_connector = ProxyConnector::from_proxy(connector, proxy).unwrap();
        proxy_connector
    };
    // need to ensure the `hyper` feature of smithy-client is enabled
    let hyper_client = aws_smithy_client::hyper_ext::Adapter::builder()
        .build(proxy);

    let client = aws_sdk_s3::client::Client::from_conf_conn(config, hyper_client);

The difference is that Adapter::builder().build() doesn't accept the hyper::Client but rather the connector itself (ProxyConnector<HttpConnector> in this case.).

Also the smithy_client is named correctly aws_smithy_client

Otherwise thanks guys, was helpful :)

elrob commented 2 years ago

Another example I eventually got working - using socks proxy:

aws-smithy-client = { version = "0.38.0", features = ["hyper"] }
hyper = "0.14.16"
hyper-proxy = "0.9.1"
hyper-socks2 = "0.6.0"
use aws_sdk_cloudsearchdomain::{Client, Config, Endpoint};
use http::Uri;
use hyper_proxy::ProxyConnector;
use hyper_socks2::SocksConnector;

...

        let proxy = {
            let mut connector = hyper::client::HttpConnector::new();
            connector.enforce_http(false);
            let socks_connector = SocksConnector {
                proxy_addr: Uri::from_static("socks5://localhost:1080"),
                auth: None,
                connector,
            };
            ProxyConnector::new(socks_connector).unwrap()
        };

        let hyper_client =
            aws_smithy_client::hyper_ext::Adapter::builder().build(proxy);

        let config = aws_config::load_from_env().await;
        let cloud_search_domain_config = Config::builder()
            .credentials_provider(config.credentials_provider().unwrap().clone())
            .endpoint_resolver(Endpoint::immutable("http://REDACTED.cloudsearch.amazonaws.com".parse().unwrap()))
            .region(config.region().unwrap().clone())
            .build();
        let client = Client::from_conf_conn(cloud_search_domain_config, hyper_client);
lcmgh commented 2 years ago

Several notes here to make above http proxy solutions work:

I'd like to see an option for the sdk to auto-determine and auto-configure proxy based on env. variables when the user desires to do so.

tonymcneil commented 2 years ago

Helpful comments here... in my case I was looking to point at a local proxy i.e. OWASP ZAP (mainly for learning and troubleshooting). This required a TLS connector to be configured on the proxy connector with the addition of the self-signed cert from the "Dynamic SSL Certificates" in ZAP > Tools > Options.

Here is what I ended up going with (following from the above examples but with some variable renaming):

let proxy = {
    // TLS cert config
    let mut f = File::open("/tmp/owasp_zap_root_ca.cer").unwrap();
    let mut buffer = vec![];
    f.read_to_end(&mut buffer).unwrap();
    let cert = Certificate::from_pem(buffer.as_slice()).unwrap();
    let connector_tls = TlsConnector::builder()
        .add_root_certificate(cert)
        // .danger_accept_invalid_certs(true) // less safe alternative to add_root_certificate(...)
        .build()
        .unwrap();

    // Proxy config
    let proxy_uri = "http://127.0.0.1:8080".parse().unwrap();
    let proxy = Proxy::new(Intercept::All, proxy_uri);
    // proxy.set_authorization(Authorization::basic("user", "pass"));
    let mut connector_http = HttpConnector::new();
    connector_http.enforce_http(false);
    let mut proxy_connector = ProxyConnector::from_proxy(connector_http, proxy).unwrap();
    proxy_connector.set_tls(Some(connector_tls));

    proxy_connector
};

Hopefully this will help with others in dealing with errors like the following when dealing with a self-signed cert in the chain:

Error: DispatchFailure(ConnectorError { err: hyper::Error(Connect, Custom { kind: Other, error: Ssl(Error { code: ErrorCode(1), cause: Some(Ssl(ErrorStack([Error { code: 337047686, library: "SSL routines", function: "tls_process_server_certificate", reason: "certificate verify failed", file: "../ssl/statem/statem_clnt.c", line: 1913 }]))) }, X509VerifyResult { code: 19, error: "self signed certificate in certificate chain" }) }), kind: Io })
lcmgh commented 2 years ago

My code stopped working after upgrading aws-smithy-client from 0.46.0 to 0.47.0.

let conn = aws_smithy_client::hyper_ext::Adapter::builder().build(env_proxy.clone().unwrap());
aws_sdk_kinesis::Client::from_conf_conn(
    config_kinesis,
    conn,
)
the trait bound `Adapter<ProxyConnector<hyper::client::HttpConnector>>: hyper::service::Service<Request<aws_smithy_http::body::SdkBody>>` is not satisfied
the trait `hyper::service::Service<Request<aws_smithy_http::body::SdkBody>>` is implemented for `Adapter<C>`
required because of the requirements on the impl of `aws_smithy_client::bounds::SmithyConnector` for `Adapter<ProxyConnector<hyper::client::HttpConnector>>`
Velfi commented 2 years ago

My code stopped working after upgrading aws-smithy-client from 0.46.0 to 0.47.0.

let conn = aws_smithy_client::hyper_ext::Adapter::builder().build(env_proxy.clone().unwrap());
aws_sdk_kinesis::Client::from_conf_conn(
    config_kinesis,
    conn,
)
the trait bound `Adapter<ProxyConnector<hyper::client::HttpConnector>>: hyper::service::Service<Request<aws_smithy_http::body::SdkBody>>` is not satisfied
the trait `hyper::service::Service<Request<aws_smithy_http::body::SdkBody>>` is implemented for `Adapter<C>`
required because of the requirements on the impl of `aws_smithy_client::bounds::SmithyConnector` for `Adapter<ProxyConnector<hyper::client::HttpConnector>>`

We recently upgraded hyper and your issue smells like a "multiple versions of one dependency" issue. Could you either:

lcmgh commented 2 years ago

We recently upgraded hyper and your issue smells like a "multiple versions of one dependency" issue. Could you either:

  • check with cargo tree -i hyper to see if multiple versions of hyper are being brought in.
  • delete your Cargo.lock and see if that fixes it.

Deleting Cargo.lock did not help.

Output of cargo tree -i hyper:

hyper v0.14.20
├── aws-config v0.46.0
│   └── kinesis-client v0.1.0 (/Users/user/Code/kinesis-client-rs)
├── aws-smithy-client v0.46.0
│   ├── aws-config v0.46.0 (*)
│   ├── aws-sdk-dynamodb v0.16.0
│   │   ├── dynomutex v0.1.7 (ssh://git@private-github/dynomutex-rs.git?rev=v0.1.7#8d0c5d0b)
│   │   │   └── kinesis-client v0.1.0 (/Users/user/Code/kinesis-client-rs)
│   │   ├── kinesis-client v0.1.0 (/Users/user/Code/kinesis-client-rs)
│   │   └── serde_dynamo v4.0.4
│   │       ├── dynomutex v0.1.7 (ssh://git@private-github/dynomutex-rs.git?rev=v0.1.7#8d0c5d0b) (*)
│   │       └── kinesis-client v0.1.0 (/Users/user/Code/kinesis-client-rs)
│   ├── aws-sdk-kinesis v0.16.0
│   │   └── kinesis-client v0.1.0 (/Users/user/Code/kinesis-client-rs)
│   ├── aws-sdk-sso v0.16.0
│   │   └── aws-config v0.46.0 (*)
│   ├── aws-sdk-sts v0.16.0
│   │   └── aws-config v0.46.0 (*)
│   └── aws-types v0.46.0
│       ├── aws-config v0.46.0 (*)
│       ├── aws-endpoint v0.46.0
│       │   ├── aws-sdk-dynamodb v0.16.0 (*)
│       │   ├── aws-sdk-kinesis v0.16.0 (*)
│       │   ├── aws-sdk-sso v0.16.0 (*)
│       │   └── aws-sdk-sts v0.16.0 (*)
│       ├── aws-http v0.46.0
│       │   ├── aws-config v0.46.0 (*)
│       │   ├── aws-sdk-dynamodb v0.16.0 (*)
│       │   ├── aws-sdk-kinesis v0.16.0 (*)
│       │   ├── aws-sdk-sso v0.16.0 (*)
│       │   └── aws-sdk-sts v0.16.0 (*)
│       ├── aws-sdk-dynamodb v0.16.0 (*)
│       ├── aws-sdk-kinesis v0.16.0 (*)
│       ├── aws-sdk-sso v0.16.0 (*)
│       ├── aws-sdk-sts v0.16.0 (*)
│       ├── aws-sig-auth v0.46.0
│       │   ├── aws-sdk-dynamodb v0.16.0 (*)
│       │   ├── aws-sdk-kinesis v0.16.0 (*)
│       │   ├── aws-sdk-sso v0.16.0 (*)
│       │   └── aws-sdk-sts v0.16.0 (*)
│       └── kinesis-client v0.1.0 (/Users/user/Code/kinesis-client-rs)
├── aws-smithy-client v0.47.0
│   └── kinesis-client v0.1.0 (/Users/user/Code/kinesis-client-rs)
├── aws-smithy-http v0.46.0
│   ├── aws-config v0.46.0 (*)
│   ├── aws-endpoint v0.46.0 (*)
│   ├── aws-http v0.46.0 (*)
│   ├── aws-sdk-dynamodb v0.16.0 (*)
│   ├── aws-sdk-kinesis v0.16.0 (*)
│   ├── aws-sdk-sso v0.16.0 (*)
│   ├── aws-sdk-sts v0.16.0 (*)
│   ├── aws-sig-auth v0.46.0 (*)
│   ├── aws-sigv4 v0.46.0
│   │   └── aws-sig-auth v0.46.0 (*)
│   ├── aws-smithy-client v0.46.0 (*)
│   ├── aws-smithy-http-tower v0.46.0
│   │   ├── aws-config v0.46.0 (*)
│   │   ├── aws-sdk-dynamodb v0.16.0 (*)
│   │   ├── aws-sdk-kinesis v0.16.0 (*)
│   │   ├── aws-sdk-sso v0.16.0 (*)
│   │   ├── aws-sdk-sts v0.16.0 (*)
│   │   └── aws-smithy-client v0.46.0 (*)
│   └── aws-types v0.46.0 (*)
├── aws-smithy-http v0.47.0
│   ├── aws-smithy-client v0.47.0 (*)
│   └── aws-smithy-http-tower v0.47.0
│       └── aws-smithy-client v0.47.0 (*)
├── hyper-proxy v0.9.1
│   └── kinesis-client v0.1.0 (/Users/user/Code/kinesis-client-rs)
├── hyper-tls v0.5.0
│   ├── aws-smithy-client v0.46.0 (*)
│   ├── aws-smithy-client v0.47.0 (*)
│   └── hyper-proxy v0.9.1 (*)
└── kinesis-client v0.1.0 (/Users/user/Code/kinesis-client-rs)
Velfi commented 2 years ago

But it did reveal the issue:

├── aws-smithy-client v0.47.0 ├── aws-smithy-http v0.46.0

It looks like your project is pulling in runtime crates from multiple versions. Those two crates should have the same version number. Could you post your Cargo.toml?

lcmgh commented 2 years ago
[package]
name = "kinesis-client"
version = "0.1.0"
edition = "2021"
readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures-util = "0.3.21"
log = "0.4"
serde = { version = "1.0.142", features = ["derive"] }
flate2 = "1.0.24"
aws-config = { version = "0.46.0", default-features = false }
aws-types = "0.46.0"
aws-sdk-kinesis = { version = "0.16.0", default-features = false }
aws-sdk-dynamodb = { version = "0.16.0", default-features = false }
dynomutex = { git = "ssh://git@private-git/dynomutex-rs.git", rev = "v0.1.7" }
rayon = "1.5.3"
tokio = { version = "1", features = ["full"] }
derive_builder = "0.11.2"
md5 = "0.7.0"
serde_dynamo = { version = "4.0.4", features = ["aws-sdk-dynamodb+0_16"] }
prost = "0.11.0"
async-trait = "0.1.57"
eyre = "0.6.8"
http = "0.2.8"
serde_with = "2.0.0"
aws-arn = "0.3.1"
metrics = "0.20.1"

# To make proxy work if there is no direct connection to AWS
hyper-proxy = "0.9.1"
hyper = "0.14.19"
aws-smithy-client = { version = "0.47.0", features = ["client-hyper"] }
headers = "0.3.7"
url = "2.2.2"

[dev-dependencies]
criterion = "0.3"
testcontainers = { version = "0.14.0" }
tracing = "0.1"
tracing-subscriber = "0.3"

[build-dependencies]
# Creates .proto files for Kinesis deaggregation
# prost-build = { version = "0.11.1" }
# protobuf-src = "1.0.5+3.19.3"

[features]
native-tls = ["aws-sdk-kinesis/native-tls", "aws-sdk-dynamodb/native-tls", "aws-smithy-client/native-tls", "aws-config/native-tls"]
default = ["native-tls"]

Does that mean I have to wait until ├── aws-smithy-client v0.46.0 using crates update to 0.47.0?

Velfi commented 2 years ago

I completely forgot that we just implemented a thing to decouple our release versions from one another. Your issue may be caused by that. Let me confer with the rest of the team on what's happening here and I'll get back to you.

In the mean time, try setting aws-smithy-client to v0.46.0 and see if that helps.

Velfi commented 2 years ago

I checked with the rest of the team and downgrading aws-smithy-client to v0.46.0 is the answer here. The AWS runtime crates should be imported at the same version as the aws-smithy runtime crates. In a way, it's good you ran into this because it highlights the need for us to better document this requirement. Thanks for that!

tshcpt commented 1 year ago

with the following crate versions:

aws-config = "0.54.1"
aws-sdk-s3 = "0.24.0"
aws-smithy-client = { version = "0.54.4", features = ["hyper", "hyper-tls"] }
hyper = { version = "0.14.24", features = ["client"] }
hyper-proxy = "0.9.1"

Had to do the following for proxy support:

use hyper_proxy::{Proxy, Intercept, ProxyConnector};
use aws_config::meta::region::RegionProviderChain;
use hyper::client::HttpConnector;
use std::env;

--snip--

    let region_provider = RegionProviderChain::default_provider().or_else("us-east-1");

    let base_config = aws_config::from_env().region(region_provider).load().await;

    let proxy = {
        let proxy_uri = env::var("http_proxy")?.parse().unwrap();
        let proxy = Proxy::new(Intercept::All, proxy_uri);
        //proxy.set_authorization(Authorization::basic("John Doe", "Agent1234"));
        let connector = HttpConnector::new();
        let proxy_connector = ProxyConnector::from_proxy(connector, proxy).unwrap();
        proxy_connector
    };
    // need to ensure the `hyper` feature of smithy-client is enabled
    let hyper_client = aws_smithy_client::hyper_ext::Adapter::builder()
        .build(proxy);
    let config = aws_sdk_s3::config::Builder::from(&base_config).http_connector(hyper_client).build();

    let client = aws_sdk_s3::client::Client::from_conf(config);
DanielCMS commented 1 year ago

In case you are having trouble with IMDS after upgrading to newer versions of aws-smithy-client, try changing

        let proxy = Proxy::new(Intercept::All, proxy_uri);

to

        let proxy = Proxy::new(Intercept::Https, proxy_uri);

in @tshcpt 's code snippet. This makes sure the SDK queries IMDS for the instance making the request, not for the proxy.

lcmgh commented 1 year ago

For reference, this is how I created proxied connections with the latest sdk.

async fn main() {
/// ....
let shared_config = config_loader(credentials_provider, region, &profile.profile, proxy)
    .load()
    .await;

aws_sdk_iam::Client::new(&shared_config);
            fetch_iam_roles_with_tags(&iam_client)
                .await
                .expect("Failed to fetch IAM roles")
}
/// Returns `ProxyConnector<HttpConnector>` if env. variable 'https_proxy' is set
pub fn determine_proxy() -> Option<ProxyConnector<HttpConnector>> {
    let proxy_url: Url = env::var("https_proxy").ok()?.parse().ok()?;
    let proxy_uri: Uri = env::var("https_proxy").ok()?.parse().ok()?;
    let mut proxy = Proxy::new(Intercept::All, proxy_uri);

    if let Some(password) = proxy_url.password() {
        proxy.set_authorization(Authorization::basic(proxy_url.username(), password));
    }

    let connector = HttpConnector::new();
    Some(ProxyConnector::from_proxy(connector, proxy).unwrap())
}

fn config_loader(
    credentials_provider: AssumeRoleProvider,
    region: Region,
    profile: &str,
    proxy: &Option<ProxyConnector<HttpConnector>>,
) -> aws_config::ConfigLoader {
    let shared_config = aws_config::from_env()
        .credentials_provider(credentials_provider)
        .region(RegionProviderChain::first_try(region))
        .profile_name(profile);

    may_add_proxy(proxy, shared_config)
}

fn may_add_proxy(
    proxy: &Option<ProxyConnector<HttpConnector>>,
    shared_config: aws_config::ConfigLoader,
) -> aws_config::ConfigLoader {
    match &proxy {
        Some(proxy) => {
            println!("Adding proxy");
            let http_client = HyperClientBuilder::new().build(proxy.clone());
            shared_config
                .http_client(http_client)
                .app_name(AppName::new("orbitwiz").expect("valid app name"))
        }
        None => shared_config,
    }
}
SarahSchn commented 1 year ago

Since I just stumbled over that Problem and the snippet from @lcmgh seems to mostly work, just a question, where does the HyperClientBuilder come from?

lcmgh commented 1 year ago

Since I just stumbled over that Problem and the snippet from @lcmgh seems to mostly work, just a question, where does the HyperClientBuilder come from?

use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder; :)

Dependency

aws-smithy-runtime = { version = "0.57.2", features = ["connector-hyper-0-14-x", "client"] }

lcmgh commented 10 months ago

I have no working solution for the latest v1 versions of the SDK. https://github.com/tafia/hyper-proxy is also not maintained anymore so it does not support hyper v1.

elrob commented 10 months ago

yeah, I have hit the same issues and temporarily have given up on upgrading...

lcmgh commented 10 months ago

this gives some hope https://github.com/seanmonstar/reqwest/issues/2107 but no timeline. would be nice if aws could sponsor the development of such things..

lcmgh commented 9 months ago

Somebody aware of any workarounds?

lcmgh commented 9 months ago

I found there is hyper_proxy2 (see https://github.com/hyperium/hyper/issues/3571#issuecomment-1952085625)

use hyper_proxy2::{Intercept, Proxy, ProxyConnector};
use url::Url;
use headers::Authorization;
use hyper::{Uri};
use hyper_util::client::legacy::connect::HttpConnector;

/// Returns `ProxyConnector<HttpConnector>` if env. variable 'https_proxy' is set
pub fn determine_proxy() -> Option<ProxyConnector<HttpConnector>> {
    let proxy_url: Url = std::env::var("https_proxy").ok()?.parse().ok()?;
    let proxy_uri: Uri = std::env::var("https_proxy").ok()?.parse().ok()?;
    let mut proxy = Proxy::new(Intercept::All, proxy_uri);

    if let Some(password) = proxy_url.password() {
        proxy.set_authorization(Authorization::basic(proxy_url.username(), password));
    }

    let connector = HttpConnector::new();
    Some(ProxyConnector::from_proxy(connector, proxy).unwrap())
}

However I cannot get it working with

aws_types::sdk_config::Builder
pub fn http_client(self, http_client: impl HttpClient + 'static) -> Self

when using

    let proxy = determine_proxy().unwrap();
    let proxy = determine_proxy().unwrap();
    let client = aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder::new().build(proxy);

    let aws_config = aws_config::load_from_env()
        .await
        .into_builder()
        .http_client(client)
        .region(Region::new("eu-central-1"))
        .build();
59 |     let client = aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder::new().build(proxy);
    |                                                                                         ----- ^^^^^ the trait `tower_service::Service<http::uri::Uri>` is not implemented for `ProxyConnector<HttpConnector>`

Is there no smithy HyperClientBuilder for v1?

jdisanti commented 9 months ago

Is there no smithy HyperClientBuilder for v1?

The SDK doesn't support hyper 1.x yet. Adding this support is being tracked in https://github.com/awslabs/aws-sdk-rust/issues/977

lcmgh commented 9 months ago

Here is a solution that works with AWS SDK v1. hyper 0.14 can still be used in there (I assumed one has to use hyper v1).

https://github.com/awslabs/aws-sdk-rust/issues/1066#issuecomment-1954073162

rcoh commented 8 months ago

A Hyper 1.0 based client now exists: https://docs.rs/aws-smithy-experimental/latest/aws_smithy_experimental/hyper_1_0/struct.HyperClientBuilder.html

jocutajar commented 8 months ago

I ended up providing custom HttpClient wrapping Reqwest and translating request / response between AWS and Reqwest, including timeout settings... it's not fun. 150 lines of fragile code.