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

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

使用 SDK 应用商店(仅限 Windows)

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

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

警告

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

注意

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

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

一般信息

SDK 商店提供以下好处:

SDK Store 配置文件特定于特定主机上的特定用户。无法将这些配置文件复制到其他主机或其他用户。这意味着您不能将开发计算机上的 SDK Store 配置文件重复用于其他主机或开发者计算机。这也意味着你不能在生产应用程序中使用 SDK Store 配置文件。

您可以通过以下方式管理 SDK 商店中的配置文件:

个人资料管理示例

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

以编程方式创建个人资料

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

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命名空间:CredentialProfilenetSDK CredentialsFile。它还使用亚马逊命名空间的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区域