I have a .Net Core app that needs to access KMS using AmazonKeyManagementServiceClient. The app uses specific AWS ProfilesLocation and a specific Profile set in the appSettings.json. The S3 client works fine and picks up the credentials from the profiles location. However the AmazonKeyManagementServiceClient fails to pick up the correct profile and associated credentials. Is there any way to have AmazonKeyManagementServiceClient pickup the credentials from the location specified in the appSettings.json without having to use the overloaded constructor public AmazonKeyManagementServiceClient(AWSCredentials credentials)
?
Here is the relevant code for appSettings.Development.json (Environment variable is set to Development):
{
"AWS": {
"Profile": "prod",
"ProfilesLocation": "C:\\Users\\my-folder-location\\.aws\\credentials",
"Region": "us-east-1"
}
}
Here is the code that is accessing the S3 and KMS
//I checked below that the AWS options are being loaded correctly
var options = _configuration.GetAWSOptions();
//The S3 client uses the correct credentials
var s3Client = options.CreateServiceClient<IAmazonS3>();
//However the KMS client is using default credentials
var kmsClient = new AmazonKeyManagementServiceClient();
Any help would be greatly appreciated.
If you want to the AmazonKeyManagementServiceClient client to be configured like the S3 client then you need to call options.CreateServiceClient<IAmazonKeyManagementService>()
like you did for S3. Just using the constructors of the service client won't have access to the IConfiguration in your application to get the credential configuration information.