Skip to main content

custom_dns/
custom-dns.rs

1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6use aws_smithy_http_client::{
7    pool::{Client as PoolClient, ConnectionPool},
8    tls::{self, rustls_provider::CryptoMode},
9    Builder,
10};
11use aws_smithy_runtime_api::client::dns::{DnsFuture, ResolveDns};
12use std::net::{IpAddr, Ipv4Addr};
13
14#[derive(Debug, Clone)]
15struct StaticResolver;
16
17impl ResolveDns for StaticResolver {
18    fn resolve_dns<'a>(&'a self, _name: &'a str) -> DnsFuture<'a> {
19        DnsFuture::ready(Ok(vec![IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))]))
20    }
21}
22
23fn main() {
24    let _legacy_client = Builder::new()
25        .tls_provider(tls::Provider::Rustls(CryptoMode::Ring))
26        .build_with_resolver(StaticResolver);
27
28    let pool = ConnectionPool::builder()
29        .dns_resolver(StaticResolver)
30        .tls_provider(tls::Provider::Rustls(CryptoMode::Ring))
31        .build_https()
32        .expect("valid connection pool");
33    let _partitioned_client =
34        PoolClient::new(&pool).expect("pool contains the anonymous partition");
35}