rust-s3
rust-s3 copied to clipboard
Attempting to load Credentials Results in 'NotEc2' Error
Describe the bug I am trying to load my default AWS configuration. This keeps generating the following error from my tests:
thread 'tests::test_handler' panicked at 'called
Result::unwrap()
on anErr
value: Not an AWS instance', src/main.rs:100:50
To Reproduce This is the offending line of code:
let credentials = Credentials::default()?;
Expected behavior This should not be generating an error as far as I can tell
Environment
- Rust version: [e.g.
1.62.1
] - lib version [e.g.
0.32.1
]
Additional context This is the link to the file: https://github.com/banyancomputer/ipfs-proof-oracle/blob/main/src/oracle/backend.rs See line 43 to see how I am calling the code in question.
** ALSO **
Does anyone know any easy way to initialize Region
and Credentials
as Constants in a file?
Ok I got around this by just using my keys as input, but I don't think this error is appropriate
@amiller68 thats a good callout, it needs better erorr, it first tries to load credentials, from various places, if none are found it tries to get some from the ec2 instance metadata, but it never tells you what its doing, needs better UX for sure
Yeah I agree. I figured out what was happening from the source code, but like either:
- the Credentials struct relies on Ec2 should be documented (not sure if you contribute to awscreds)
- or it just shouldn't rely on that lol
I ended up getting to where I needed to be by using hard-coded access keys (not ideal but I can probably work something out with env vars)
@durch do you know a good way to load creds as some sort of static/constant struct? I'm new to rust and keep getting compiler errors :(
I'd suggest defining them in the environment of where you're running this, that way you don't need to code anything in
@durch, I was referring to when you eventually have to reference a awscreds::Credentials
instance when initializing a new s3 client. I almost found a solution with lazy_static
, but I found I still have to clone the Static struct before passing it to bucket::new
.
You should be able to do Credentials::default()
, and it would pick them up from the environment.
let bucket = Bucket::new(
"test-bucket",
"eu-central-1".parse().unwrap(),
&Credentials::default()).unwrap();
^ Not sure if bucket takes a reference or value