Aws sdk Linux上的AWS.NETSDK
我目前正在将第三方制作的ASP.NET应用程序从Windows移动到Linux。我阅读了文档,没有任何迹象表明这应该是一个问题,但很遗憾Aws sdk Linux上的AWS.NETSDK,aws-sdk,aws-sdk-net,Aws Sdk,Aws Sdk Net,我目前正在将第三方制作的ASP.NET应用程序从Windows移动到Linux。我阅读了文档,没有任何迹象表明这应该是一个问题,但很遗憾 var profile = new CredentialProfile(profileName, credentials) { Region = RegionEndpoint.EUWest1 }; var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(prof
var profile = new CredentialProfile(profileName, credentials) {
Region = RegionEndpoint.EUWest1
};
var netSDKFile = new NetSDKCredentialsFile();
netSDKFile.RegisterProfile(profile);
引发以下异常
Unhandled Exception: Amazon.Runtime.AmazonClientException: The encrypted store is not available. This may be due to use of a non-Windows operating system or Windows Nano Server, or the current user account may not have its profile loaded.
at Amazon.Util.Internal.SettingsManager.EnsureAvailable()
at Amazon.Runtime.CredentialManagement.NetSDKCredentialsFile..ctor()
Linux是否不支持Amazon.NETSDK(或其一部分)?如果是这样,是否有可能的解决办法?在大多数情况下,Windows支持的Linux上不支持的东西很少。我脑子里除了
NetSDKCredentialsFile
之外,想不出任何东西,这是因为它使用Win32 API加密凭据
您可以使用
SharedCredentialsFile
在~/.aws/credentials
下存储的凭据文件中注册配置文件。这是所有其他AWS SDK和工具支持的相同凭证。在大多数情况下,Windows支持的Linux上不支持的凭证很少。我脑子里除了NetSDKCredentialsFile
之外,想不出任何东西,这是因为它使用Win32 API加密凭据
您可以使用
SharedCredentialsFile
在~/.aws/credentials
下存储的凭据文件中注册配置文件。这是所有其他AWS SDK和工具支持的同一凭证。根据Norm的回答,我找到了解释如何使用共享凭证的资源:
这就是我以前使用NetSDK凭据的方式,它不适用于Linux/Mac OS:
//Try this code on a non-Windows platform and you will see the above error
var options = new CredentialProfileOptions
{
AccessKey = "access_key",
SecretKey = "secret_key"
};
var profile = new CredentialProfile("default", options);
profile.Region = RegionEndpoint.USWest1;
NetSDKCredentialsFile file = new NetSDKCredentialsFile();
file.RegisterProfile(profile);
但我随后能够使用这个示例来使用SharedRedentials:
var credProfileStoreChain = new CredentialProfileStoreChain();
if (credProfileStoreChain.TryGetAWSCredentials("default", out AWSCredentials awsCredentials))
{
Console.WriteLine("Access Key: " + awsCredentials.GetCredentials().AccessKey);
Console.WriteLine("Secret Key: " + awsCredentials.GetCredentials().SecretKey);
}
Console.WriteLine("Hello World!");
然后,您将能够看到您的代码,并能够访问密钥:
Access Key: A..................Q
Secret Key: 8.......................................p
Hello World!
然后,我使用System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform()(因为我在Windows和Linux上都使用此代码)来确定要使用哪些凭据:
using System.Runtime.InteropServices;
//NETSDK Credentials only work on Windows - must use SharedCredentials on Linux
bool isLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
if (isLinux) {
//Use SharedCredentials
} else {
//Use NetSDKCredentials
}
您可能会发现AWS文档的这一部分也很有帮助:根据Norm的回答,我找到了这个资源,它解释了如何使用共享凭证: 这就是我以前使用NetSDK凭据的方式,它不适用于Linux/Mac OS:
//Try this code on a non-Windows platform and you will see the above error
var options = new CredentialProfileOptions
{
AccessKey = "access_key",
SecretKey = "secret_key"
};
var profile = new CredentialProfile("default", options);
profile.Region = RegionEndpoint.USWest1;
NetSDKCredentialsFile file = new NetSDKCredentialsFile();
file.RegisterProfile(profile);
但我随后能够使用这个示例来使用SharedRedentials:
var credProfileStoreChain = new CredentialProfileStoreChain();
if (credProfileStoreChain.TryGetAWSCredentials("default", out AWSCredentials awsCredentials))
{
Console.WriteLine("Access Key: " + awsCredentials.GetCredentials().AccessKey);
Console.WriteLine("Secret Key: " + awsCredentials.GetCredentials().SecretKey);
}
Console.WriteLine("Hello World!");
然后,您将能够看到您的代码,并能够访问密钥:
Access Key: A..................Q
Secret Key: 8.......................................p
Hello World!
然后,我使用System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform()(因为我在Windows和Linux上都使用此代码)来确定要使用哪些凭据:
using System.Runtime.InteropServices;
//NETSDK Credentials only work on Windows - must use SharedCredentials on Linux
bool isLinux = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
if (isLinux) {
//Use SharedCredentials
} else {
//Use NetSDKCredentials
}
您可能会发现AWS文档的这一部分也很有用: