Regions and Profiles #640
Answered
by
keithsharp
keithsharp
asked this question in
Q&A
-
I have a
I am trying to use the 'research' profile using the following code: #[tokio::main]
async fn main() -> Result<(), Error> {
let sdk_config = aws_config::from_env().load().await;
let region = Region::new("eu-west-1")
let research = ProfileFileCredentialsProvider::builder().profile_name("research").build();
let config = Builder::from(&sdk_config).credentials_provider(research).region(region).build();
let client = Client::from_conf(config);
let req = client.describe_vpcs();
let resp = req.send().await?;
println!("{:?}", resp);
Ok(())
} When I run the program I get the error:
Using the default profile works, as does using the CLI equivalent: aws ec2 describe-vpcs --profile research Any ideas what I'm doing wrong? Thanks, Keith. |
Beta Was this translation helpful? Give feedback.
Answered by
keithsharp
Oct 16, 2022
Replies: 2 comments
-
I've solved my problem by using code from #443. My working code: use std::env;
use aws_config::default_provider::region::DefaultRegionChain;
use aws_config::default_provider::credentials::DefaultCredentialsChain;
use aws_sdk_ec2::Error;
use aws_sdk_ec2::Client;
async fn main() -> Result<(), Error> {
let profile = env::args().skip(1).next().expect("profile to use is required");
let region = DefaultRegionChain::builder().profile_name(&profile).build().region().await;
let creds = DefaultCredentialsChain::builder()
.profile_name(&profile)
.region(region.clone())
.build()
.await;
let config = aws_config::from_env().credentials_provider(creds).region(region).load().await;
let client = Client::new(&config);
let req = client.describe_vpcs();
let resp = req.send().await?;
println!("{:?}", resp);
Ok(())
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
keithsharp
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've solved my problem by using code from #443. My working code: