@@ -208,22 +208,39 @@ namespace Aws
208208#endif
209209 }
210210
211- EC2MetadataClient::EC2MetadataClient (const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& credentialConfig,
212- const char * endpoint)
213- : AWSHttpResourceClient(
214- [&credentialConfig]() -> ClientConfiguration{
215- Aws::Client::ClientConfiguration clientConfig{credentialConfig.profile .c_str ()};
216- clientConfig.region = credentialConfig.region ;
217- clientConfig.credentialProviderConfig = credentialConfig;
218- clientConfig.requestTimeoutMs = credentialConfig.imdsConfig .metadataServiceTimeout * 1000 ;
219- clientConfig.retryStrategy = credentialConfig.imdsConfig .imdsRetryStrategy ;
220- return clientConfig;
221- }(),
222- EC2_METADATA_CLIENT_LOG_TAG),
223- m_endpoint (endpoint),
224- m_disableIMDS (credentialConfig.imdsConfig.disableImds),
225- m_tokenRequired (true ),
226- m_disableIMDSV1 (credentialConfig.imdsConfig.disableImdsV1) {
211+ EC2MetadataClient::EC2MetadataClient (
212+ const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& credentialConfig,
213+ const char * endpoint)
214+ : AWSHttpResourceClient(
215+ [&credentialConfig]() -> Aws::Client::ClientConfiguration {
216+ Aws::Client::ClientConfiguration clientConfig{credentialConfig.profile .c_str ()};
217+ clientConfig.region = credentialConfig.region ;
218+ clientConfig.credentialProviderConfig = credentialConfig;
219+
220+ // pick an IMDS strategy: use caller's if present; else synthesize from attempts
221+ auto imdsRetry = credentialConfig.imdsConfig .imdsRetryStrategy ;
222+ if (!imdsRetry) {
223+ const long totalAttempts =
224+ (credentialConfig.imdsConfig .metadataServiceNumAttempts > 0 )
225+ ? credentialConfig.imdsConfig .metadataServiceNumAttempts
226+ : 1 ; // 1 total attempt => 0 retries
227+ const long maxRetries = std::max<long >(0 , totalAttempts - 1 );
228+ imdsRetry = Aws::MakeShared<Aws::Client::DefaultRetryStrategy>(
229+ EC2_METADATA_CLIENT_LOG_TAG, maxRetries, /* scaleMs=*/ 1000 );
230+ }
231+
232+ // critical: set BOTH the direct pointer and the factory fallback
233+ clientConfig.retryStrategy = imdsRetry;
234+ clientConfig.configFactories .retryStrategyCreateFn = [imdsRetry]() { return imdsRetry; };
235+
236+ return clientConfig;
237+ }(),
238+ EC2_METADATA_CLIENT_LOG_TAG),
239+ m_endpoint (endpoint),
240+ m_disableIMDS (credentialConfig.imdsConfig.disableImds),
241+ m_tokenRequired (true ),
242+ m_disableIMDSV1 (credentialConfig.imdsConfig.disableImdsV1)
243+ {
227244#if defined(DISABLE_IMDSV1)
228245 m_disableIMDSV1 = true ;
229246 AWS_LOGSTREAM_TRACE (m_logtag.c_str (), " IMDSv1 had been disabled at the SDK build time" );
0 commit comments