Closed tsuyoshizawa closed 1 year ago
If you were expecting InstanceProfileCredentialsProvider
to be picked up, this is the relevant error message:
InstanceProfileCredentialsProvider(): Failed to load credentials from IMDS.
Since the error is intermittent (once a week), and based on previous issue reports, this is probably caused by latency in the IMDS endpoint. You can enable the SDK client-side metrics to obtain more insights on the duration of the credential fetching step over time.
To set expectations, EC2 instance credentials need to communicate with the IMDS endpoint to obtain the temporary session token, this process will be affected by connectivity and latency issues, so credential fetching errors can occur.
@debora-ito Thank you for confirming what the issue is.
I looked into the latency issue and the advice you gave me and found the following similar problem and solution. https://medium.com/expedia-group-tech/service-slow-to-retrieve-aws-credentials-ebc02a38e95b
It seems to be a known issue, as described in that blog. I should have looked into this GitHub Issue more.
The sample you provided to try to get metrics adds a MetricPublisher
through the overrideConfiguration
method in the S3Client
. However, the S3Presigner
class does not seem to have an API to add a similar MetricPublisher
.
If I want to measure with a mechanism like the sample, is it possible to do so if there is a similar API?
I hope this will be a reference for improving the AWS SDK Java library.
However, the S3Presigner class does not seem to have an API to add a similar MetricPublisher?
That's because S3Presigner simply generates a signed request, the SDK does not control how that request will be sent to the service so there's no way to track the duration of the steps in the request lifecycle. I apologize, I should have noticed you were using S3Presigner before I suggested the client metrics.
Let us know if you have any other question.
Thank you. I will try to measure the latency slowdown on my end.
If AWS provides a solution to slow latency with that, please let me know. until then, you can have this issue closed.
Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
I am leaving this as a note because I may have possibly solved the problem.
As mentioned in the comments above, I am using S3Presigner
for my project.
I specified the same CredentialsProvider
and Region
that I use for the upload process, and the timeout that used to occur only once a week for all instances no longer occurs.
S3Presigner.create()
S3Presigner
.builder()
.credentialsProvider(awsCredentialsProviderChain)
.region(awsRegionProviderChain.getRegion)
.build()
I am skeptical because both ultimately use the CredentialsProvider
generated by InstanceProfileCredentialsProvider.create()
.
I am using like this:
@Configuration
@AllArgsConstructor
public class AmazonS3Config {
private final AwsProperties awsProperties;
@Bean("awsCredentials")
public AwsCredentialsProvider awsCredentials() {
return DefaultCredentialsProvider.create();
}
@Bean("s3AsyncClient")
public S3AsyncClient s3AsyncClient(@Qualifier("awsCredentials") AwsCredentialsProvider awsCredentials) {
return S3AsyncClient
.builder()
.credentialsProvider(awsCredentials)
.region(Region.of(awsProperties.getS3().getRegion()))
.build();
}
@Bean("s3Client")
public S3Client s3Client(@Qualifier("awsCredentials") AwsCredentialsProvider awsCredentials) {
return S3Client
.builder()
.credentialsProvider(awsCredentials)
.region(Region.of(awsProperties.getS3().getRegion()))
.build();
}
}
It is OK on my local. But, after deployed to VM error occurred like above.
I am using Spring Boot 3.3.5 n AWS SDK S3 2.x.x
Any suggestions?
Thanks
Describe the bug
The system I am working on handles S3 access using IAM roles. This access processing is done using the
InstanceProfileCredentialsProvider
in the AWS Java SDK.The following stocktrace began to spit out around the end of January 2023. Curiously, about once a week at about the same time, all application servers began to spit out the same error.
Regarding the processing, there is an error at the point where
S3Presigner.create()
is called andpresignGetObject
is executed.I am not currently aware of any changes made to the infrastructure environment around AWS prior to this issue.
Expected Behavior
Continuous access to S3 without a single credentials loading error.
Current Behavior
Get an error reading credentials only once a week.
Reproduction Steps
No reproducible steps.
Possible Solution
No response
Additional Information/Context
No response
AWS Java SDK version used
AWS SDK 2.20.47
JDK version used
OpenJDK Runtime Environment Corretto-11.0.18.10.1 (build 11.0.18+10-LTS)
Operating System and version
Amazon Linux release 2 (Karoo)