Skip to content

Commit 7ae4110

Browse files
committed
init commit for slow empty credentials issue
1 parent 54c9ab3 commit 7ae4110

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/aws-cpp-sdk-core/include/aws/core/internal/AWSHttpResourceClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ namespace Aws
160160
};
161161

162162
void AWS_CORE_API InitEC2MetadataClient();
163+
void AWS_CORE_API InitEC2MetadataClient(const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& credentialConfig);
163164
void AWS_CORE_API CleanupEC2MetadataClient();
164165
std::shared_ptr<EC2MetadataClient> AWS_CORE_API GetEC2MetadataClient();
165166

src/aws-cpp-sdk-core/source/config/EC2InstanceProfileConfigLoader.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ namespace Aws
4040
}
4141

4242
EC2InstanceProfileConfigLoader::EC2InstanceProfileConfigLoader(const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& credentialConfig)
43-
: m_ec2metadataClient(Aws::MakeShared<Aws::Internal::EC2MetadataClient>(EC2_INSTANCE_PROFILE_LOG_TAG, credentialConfig))
44-
{}
43+
//: m_ec2metadataClient(Aws::MakeShared<Aws::Internal::EC2MetadataClient>(EC2_INSTANCE_PROFILE_LOG_TAG, credentialConfig))
44+
{
45+
Aws::Internal::InitEC2MetadataClient(credentialConfig);
46+
m_ec2metadataClient = Aws::Internal::GetEC2MetadataClient();
47+
}
4548

4649
bool EC2InstanceProfileConfigLoader::LoadInternal()
4750
{

src/aws-cpp-sdk-core/source/internal/AWSHttpResourceClient.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,46 @@ namespace Aws
441441
static std::shared_ptr<EC2MetadataClient> s_ec2metadataClient(nullptr);
442442
#endif
443443

444+
void InitEC2MetadataClient(const Aws::Client::ClientConfiguration::CredentialProviderConfiguration& credentialConfig) {
445+
if (s_ec2metadataClient)
446+
{
447+
return;
448+
}
449+
Aws::String ec2MetadataServiceEndpoint = Aws::Environment::GetEnv("AWS_EC2_METADATA_SERVICE_ENDPOINT");
450+
if (ec2MetadataServiceEndpoint.empty())
451+
{
452+
Aws::String ec2MetadataServiceEndpointMode = Aws::Environment::GetEnv("AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE").c_str();
453+
if (ec2MetadataServiceEndpointMode.length() == 0 )
454+
{
455+
ec2MetadataServiceEndpoint = "http://169.254.169.254"; //default to IPv4 default endpoint
456+
}
457+
else
458+
{
459+
if (ec2MetadataServiceEndpointMode.length() == 4 )
460+
{
461+
if (Aws::Utils::StringUtils::CaselessCompare(ec2MetadataServiceEndpointMode.c_str(), "ipv4"))
462+
{
463+
ec2MetadataServiceEndpoint = "http://169.254.169.254"; //default to IPv4 default endpoint
464+
}
465+
else if (Aws::Utils::StringUtils::CaselessCompare(ec2MetadataServiceEndpointMode.c_str(), "ipv6"))
466+
{
467+
ec2MetadataServiceEndpoint = "http://[fd00:ec2::254]";
468+
}
469+
else
470+
{
471+
AWS_LOGSTREAM_ERROR(EC2_METADATA_CLIENT_LOG_TAG, "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE can only be set to ipv4 or ipv6, received: " << ec2MetadataServiceEndpointMode );
472+
}
473+
}
474+
else
475+
{
476+
AWS_LOGSTREAM_ERROR(EC2_METADATA_CLIENT_LOG_TAG, "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE can only be set to ipv4 or ipv6, received: " << ec2MetadataServiceEndpointMode );
477+
}
478+
}
479+
}
480+
AWS_LOGSTREAM_INFO(EC2_METADATA_CLIENT_LOG_TAG, "Using IMDS endpoint: " << ec2MetadataServiceEndpoint);
481+
s_ec2metadataClient = Aws::MakeShared<EC2MetadataClient>(EC2_METADATA_CLIENT_LOG_TAG, credentialConfig, ec2MetadataServiceEndpoint.c_str());
482+
}
483+
444484
void InitEC2MetadataClient()
445485
{
446486
if (s_ec2metadataClient)

0 commit comments

Comments
 (0)