Skip to content

Commit ad0fd27

Browse files
committed
Additional changes
1 parent 385d583 commit ad0fd27

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

core/imds/src/main/java/software/amazon/awssdk/imds/internal/DefaultEc2MetadataClientWithFallback.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private DefaultEc2MetadataClientWithFallback(Ec2MetadataBuilder builder) {
8080

8181
this.imdsV1FallbackEnabled = !resolveImdsV1Disabled();
8282

83-
this.tokenCache = CachedSupplier.builder(() -> RefreshResult.builder(this.getToken())
83+
this.tokenCache = CachedSupplier.builder(() -> RefreshResult.builder(this.getTokenWithFallback())
8484
.staleTime(Instant.now().plus(tokenTtl))
8585
.build())
8686
.cachedValueName(toString())
@@ -122,7 +122,7 @@ public Ec2MetadataResponse get(String path) {
122122
RetryPolicyContext retryPolicyContext = RetryPolicyContext.builder().retriesAttempted(attempt).build();
123123
try {
124124
if (token == null || token.isExpired()) {
125-
token = getTokenWithFallback();
125+
token = tokenCache.get();
126126
}
127127
return sendRequest(path, token != null ? token.value() : null);
128128
} catch (UncheckedIOException | RetryableException e) {
@@ -154,13 +154,13 @@ public Ec2MetadataResponse get(String path) {
154154
}
155155

156156
/**
157-
* Gets token with fallback logic that matches EC2MetadataUtils behavior.
157+
* Gets token with fallback logic that can be cached.
158158
* If token retrieval fails with 400 error, throws exception.
159159
* Otherwise, returns null to indicate fallback to IMDSv1.
160160
*/
161161
private Token getTokenWithFallback() {
162162
try {
163-
return tokenCache.get();
163+
return getToken();
164164
} catch (Exception e) {
165165
boolean is400ServiceException = e instanceof Ec2MetadataClientException
166166
&& ((Ec2MetadataClientException) e).statusCode() == 400;

0 commit comments

Comments
 (0)