in src/Aspire.Hosting.AWS/SdkUtilities.cs [104:157]
private static async Task ValidateSdkConfigAsync(ILogger logger, IAWSSDKConfig config, bool defaultConfig)
{
// Cache key used to make sure we only validate a SDK configuration once.
var cacheKey = $"Profile:{config.Profile},Region:{config.Region?.SystemName}";
await _semaphore.WaitAsync();
try
{
if (_validatedSdkConfigs.Contains(cacheKey))
{
return;
}
var stsConfig = new AmazonSecurityTokenServiceConfig();
if (config.Region != null)
stsConfig.RegionEndpoint = config.Region;
if (!string.IsNullOrEmpty(config.Profile))
stsConfig.Profile = new Amazon.Profile(config.Profile);
try
{
using var stsClient = new AmazonSecurityTokenServiceClient(stsConfig);
stsClient.BeforeRequestEvent += ConfigureUserAgentString;
// Make an AWS call to an API that doesn't require permissions to confirm
// the sdk config is able to connect to AWS.
var response = await stsClient.GetCallerIdentityAsync(new GetCallerIdentityRequest());
if (defaultConfig)
logger.LogInformation("Default AWS SDK config validated for account: {accountId}", response.Account);
else
logger.LogInformation("AWS SDK config validated for account: {accountId}", response.Account);
_validatedSdkConfigs.Add(cacheKey);
}
catch (Exception)
{
if (defaultConfig)
{
logger.LogWarning("Failed to connect to AWS using default AWS SDK config");
}
else
{
logger.LogError("Failed to connect to AWS using AWS SDK config: {configSettings}", cacheKey);
}
_validatedSdkConfigs.Add(cacheKey);
}
}
finally
{
_semaphore.Release();
}
}