View a markdown version of this page

使用 SDK Store(仅适用于 Windows) - Amazon SDK for .NET (V3)
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

Amazon SDK for .NET V3 的支持已到期。

我们建议您迁移到 Amazon SDK for .NET V4 。有关如何迁移的更多详细信息和信息,请参阅我们的终止支持公告

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 SDK Store(仅适用于 Windows)

(请务必查看重要的警告和指南。)

在 Windows 上,SDK 商店是另一个为 Amazon SDK for .NET 应用程序创建配置文件和存储加密凭据的地方。它位于 %USERPROFILE%\AppData\Local\AWSToolkit\RegisteredAccounts.json。在开发过程中,您可以使用 SDK Store 作为共享 Amazon 凭证文件的替代方案。

警告

为了避免安全风险,在开发专用软件或处理真实数据时,请勿使用 IAM 用户进行身份验证,而是使用与身份提供者的联合身份验证,例如 Amazon IAM Identity Center

注意

本主题中的信息适用于需要手动获取和管理短期或长期凭证的情况。有关短期和长期凭证的更多信息,请参阅Amazon SDKs 和工具参考指南中的其他身份验证方式

要了解最佳安全实践,请使用 Amazon IAM Identity Center,如中所述配置 SDK 身份验证

一般信息

SDK Store 具有以下优势:

SDK Store 配置文件针对特定主机上的特定用户。无法将这些配置文件复制到其他主机或其他用户。这表示,您无法在其它主机或开发人员计算机上重用您的开发计算机上的 SDK Store 配置文件。这同时也表示,您不能在生产应用程序中使用 SDK Store 配置文件。

您可通过多种方式管理 SDK Store 中的配置文件。

配置文件管理示例

以下示例说明如何在 SDK Store 中以编程方式创建和更新配置文件。

以编程方式创建配置文件

本示例向您展示了如何以编程方式创建配置文件并将其保存到 SDK Store。它使用 Amazon.Runtime 的以下类。 CredentialManagement命名空间:CredentialProfileOptionsCredentialProfile、和 Net SDKCredentials File

using Amazon.Runtime.CredentialManagement; ... // Do not include credentials in your code. WriteProfile("my_new_profile", SecurelyStoredKeyID, SecurelyStoredSecretAccessKey); ... void WriteProfile(string profileName, string keyId, string secret) { Console.WriteLine($"Create the [{profileName}] profile..."); var options = new CredentialProfileOptions { AccessKey = keyId, SecretKey = secret }; var profile = new CredentialProfile(profileName, options); var netSdkStore = new NetSDKCredentialsFile(); netSdkStore.RegisterProfile(profile); }
警告

这样的代码通常不会出现在您的应用程序中。如果应用程序中包含明文密钥,请采取适当的预防措施,确保在代码、网络甚至计算机内存中都看不到明文密钥。

下面是通过本示例创建的配置文件。

"[generated GUID]" : { "AWSAccessKey" : "01000000D08...[etc., encrypted access key ID]", "AWSSecretKey" : "01000000D08...[etc., encrypted secret access key]", "ProfileType" : "AWS", "DisplayName" : "my_new_profile", }

以编程方式更新现有配置文件

本示例向您展示了如何以编程方式更新之前创建的配置文件。它使用 Amazon.Runtime 的以下类。 CredentialManagement命名空间:CredentialProfile网络SDKCredentials文件。它还使用 Amazon 命名空间的RegionEndpoint类。

using Amazon.Runtime.CredentialManagement; ... AddRegion("my_new_profile", RegionEndpoint.USWest2); ... void AddRegion(string profileName, RegionEndpoint region) { var netSdkStore = new NetSDKCredentialsFile(); CredentialProfile profile; if (netSdkStore.TryGetProfile(profileName, out profile)) { profile.Region = region; netSdkStore.RegisterProfile(profile); } }

以下是更新的配置文件。

"[generated GUID]" : { "AWSAccessKey" : "01000000D08...[etc., encrypted access key ID]", "AWSSecretKey" : "01000000D08...[etc., encrypted secret access key]", "ProfileType" : "AWS", "DisplayName" : "my_new_profile", "Region" : "us-west-2" }
注意

您也可以使用其他方法在其他位置设置 Amazon 区域。有关更多信息,请参阅 配置 Amazon 区域