我正在使用.Net Core 2.0 / Console应用程序,并且除了AWS KMS API以外,对于大多数AWS功能都使用AWS SDK非常成功。 没有一个AWS KMS API方法调用成功。不幸的是,我无法捕获异常。
调用AWS KMS API UpdateKeyDescriptionResponse updateKeyDescriptionResponse = await kmsClient.UpdateKeyDescriptionAsync( updateKeyDescriptionRequest);
我尝试使用root用户和IAM用户的凭据。两者都不起作用。我对DynamoDB API和IoT API使用了类似的方法,并且都成功了。谁能指出我在想什么?
请参见下面的代码:
public async Task<bool> ImportKeyIntoKMS(){
try{
var builder = new ConfigurationBuilder()
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.Development.json");
Configuration = builder.Build();
var options = Configuration.GetAWSOptions();
var chain = new CredentialProfileStoreChain(options.ProfilesLocation);
Amazon.Runtime.AWSCredentials awsCredentials;
if (chain.TryGetAWSCredentials(options.Profile, out awsCredentials)){
// Use awsCredentials
}
AmazonKeyManagementServiceConfig clientConfig = new AmazonKeyManagementServiceConfig();
clientConfig.RegionEndpoint = options.Region;
var kmsClient = new AmazonKeyManagementServiceClient(awsCredentials, clientConfig);
String keyId = "arn:aws:kms:us-east-2:1502100XXXXX:key/a10ef235-0d07-47ab-9e8a-c0c7e092b5cc";
UpdateKeyDescriptionRequest updateKeyDescriptionRequest = new UpdateKeyDescriptionRequest();
updateKeyDescriptionRequest.Description = "Test Description";
updateKeyDescriptionRequest.KeyId = keyId;
UpdateKeyDescriptionResponse updateKeyDescriptionResponse = await kmsClient.UpdateKeyDescriptionAsync( updateKeyDescriptionRequest);
}
catch(AmazonClientException ex){
string test = ex.StackTrace + ex.InnerException;
}
return isValueSaved;
}