

 适用于 .NET 的 AWS SDK V3 已进入维护模式。

我们建议您迁移到 [适用于 .NET 的 AWS SDK V4](https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/welcome.html)。有关如何迁移的更多详细信息和信息，请参阅我们的[维护模式公告](https://aws.amazon.com/blogs/developer/aws-sdk-for-net-v3-maintenance-mode-announcement/)。

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

# 使用 SDK Store（仅适用于 Windows）
<a name="sdk-store"></a>

（请务必查看[重要的警告和指南](net-dg-legacy-creds.md#net-dg-config-creds-warnings-and-guidelines)。）

在 Windows 上，*SDK 商店*是另一个为 适用于 .NET 的 AWS SDK 应用程序创建配置文件和存储加密凭据的地方。它位于 `%USERPROFILE%\AppData\Local\AWSToolkit\RegisteredAccounts.json`。在开发过程中，您可以使用 SDK Store 作为[共享 AWS 凭证文件](creds-file.md)的替代方案。

**警告**  
为了避免安全风险，在开发专用软件或处理真实数据时，请勿使用 IAM 用户进行身份验证，而是使用与身份提供者的联合身份验证，例如 [AWS IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html)。

**注意**  
本主题中的信息适用于需要手动获取和管理短期或长期凭证的情况。有关短期和长期凭证的更多信息，请参阅*AWS SDKs 和工具参考指南*中的[其他身份验证方式](https://docs.aws.amazon.com/sdkref/latest/guide/access-users.html)。  
要了解最佳安全实践，请使用 AWS IAM Identity Center，如中所述[配置 SDK 身份验证](creds-idc.md)。

## 一般信息
<a name="sdk-store-general-info"></a>

SDK Store 具有以下优势：
+ SDK Store 中的凭证将进行加密，并且 SDK Store 驻留在用户的主目录中。这将限制意外泄露凭证的风险。
+ SDK Store 还向[AWS Tools for Windows PowerShell](https://docs.aws.amazon.com/powershell/latest/userguide/)和[AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/AWSToolkitVS/latest/UserGuide/)提供凭证。

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

您可通过多种方式管理 SDK Store 中的配置文件。
+ 在 [AWS Toolkit for Visual Studio](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/credentials.html) 中使用图形用户界面（GUI）。
+ 使用 [Amazon.Runtime。 CredentialManagement](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Runtime/NRuntimeCredentialManagement.html) 适用于 .NET 的 AWS SDK API 的命名空间，如本主题后面所示。
+ 使用来自 [AWS Tools for Windows PowerShell](https://docs.aws.amazon.com/powershell/latest/userguide/specifying-your-aws-credentials.html) 的命令；例如，`Set-AWSCredential` 和 `Remove-AWSCredentialProfile`。

## 配置文件管理示例
<a name="sdk-store-examples"></a>

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

### 以编程方式创建配置文件
<a name="sdk-store-create-programmatically"></a>

本示例向您展示了如何以编程方式创建配置文件并将其保存到 SDK Store。它使用 [Amazon.Runtime 的以下类。 CredentialManagement](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Runtime/NRuntimeCredentialManagement.html)命名空间:[CredentialProfileOptions[CredentialProfile](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Runtime/TCredentialProfile.html)](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Runtime/TCredentialProfileOptions.html)、和 [Net SDKCredentials File](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Runtime/TNetSDKCredentialsFile.html)。

```
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",
}
```

### 以编程方式更新现有配置文件
<a name="sdk-store-update-programmatically"></a>

本示例向您展示了如何以编程方式更新之前创建的配置文件。它使用 [Amazon.Runtime 的以下类。 CredentialManagement](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Runtime/NRuntimeCredentialManagement.html)命名空间：[CredentialProfile](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Runtime/TCredentialProfile.html)和[网络SDKCredentials文件](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Runtime/TNetSDKCredentialsFile.html)。它还使用 [Amazon](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Amazon/N.html) 命名空间的[RegionEndpoint](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Amazon/TRegionEndpoint.html)类。

```
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"
}
```

**注意**  
您也可以使用其他方法在其他位置设置 AWS 区域。有关更多信息，请参阅 [配置 AWS 区域](net-dg-region-selection.md)。