

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# パラメータストアの設定
<a name="configure-store"></a>

Parameter Store は の一機能です AWS Systems Manager。設定データ管理と機密管理のための安全な階層型ストレージを提供します。パスワード、データベース文字列、Amazon マシンイメージ (AMI) ID、ライセンスコードなどのデータをパラメータ値として保存できます。

## .NET Framework アプリケーションで Parameter Store を使用するための前提条件
<a name="configure-store-prereq"></a>
+ アクティブな AWS アカウント
+ [Microsoft Visual Studio](https://visualstudio.microsoft.com/downloads/)、インストール済み
+ AWS Command Line Interface (AWS CLI) バージョン 2、 にアクセスするようにインストールおよび設定 ( AWS アカウント [手順](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)を参照)
+ AWS Toolkit for Visual Studio、設定済み ([手順](https://docs.aws.amazon.com/toolkit-for-visual-studio/latest/user-guide/setup.html)を参照)
+ [Secrets Manager コンソールまたは を使用して作成された Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-create-console.html) パラメータ [AWS CLI](https://docs.aws.amazon.com/systems-manager/latest/userguide/param-create-cli.html)

## 例
<a name="configure-store-example"></a>

ASP.NET Core ウェブアプリケーションまたは API で Parameter Store から値を取得するには:

1.  ASP.NET Core ウェブ API に次の NuGet パッケージを追加します。

   ```
   Amazon.Extensions.Configuration.SystemsManager
   ```

1. `Program.cs` ファイルで、次の変更を行います。
   + `using` ステートメント (1) を追加します。

     ```
     using Amazon;
     using Amazon.Extensions.NETCore.Setup;
     ```
   +  AWS Systems Manager 設定 (2) を追加します。

     ```
     builder.Configuration.AddSystemsManager("/dev/myapp", new AWSOptions
     {
         Region = RegionEndpoint.EUWest2
     });
     ```  
![\[Parameter Store にアクセスするための Program.cs ファイルの変更\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/modernization-net-applications-security/images/ps-program-cs.png)
**注記**  
`/myapp/dev` および `RegionEndPoint`パラメータは動的に呼び出すか、環境変数 () から呼び出す必要があります`Region = RegionEndpoint.GetBySystemName("eu-west-2")`。本番環境では、これらの値をハードコードしないでください。

1. 新しいクラスファイルを作成し、 という名前を付けます`ParameterOptions.cs`。ファイルを開き、次のコードを追加します。

   ```
   public class ParameterOptions
       {
           public const string ParameterName = "Tenant";
           public string key1 { get; set; } = string.Empty;
           public string key2 { get; set; } = string.Empty;
       }
   ```

1. Parameter Store から値を取得するには、コントローラークラスファイル ( など) に次の変更を加えます`ValuesController.cs`。
   + コンストラクタ (1) を追加します。

     ```
     private readonly IConfiguration _configuration;
     public ParametersController(IConfiguration configuration)
     {
         _configuration = configuration;
     }
     ```
   + パラメータストア (2) から値を取得します。

     ```
     var parameterOptions = new ParameterOptions();
     _configuration.GetSection(ParameterOptions.ParameterName).Bind(parameterOptions);
     
     return new string[] {
         parameterOptions.key1,
         parameterOptions.key2
     };
     ```  
![\[Parameter Store から値を取得するためのコントローラークラスファイルの変更\]](http://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/modernization-net-applications-security/images/ps-controller-class.png)

## リソース
<a name="configure-store-resources"></a>
+ [AWS Secrets Manager ローテーション Lambda 関数](https://github.com/aws-samples/aws-secrets-manager-rotation-lambdas) (GitHub リポジトリ)
+ [AWS Systems Manager の .NET Configuration Extension、サンプルフォルダ](https://github.com/aws/aws-dotnet-extensions-configuration/tree/master/samples/Samples) (GitHub リポジトリ)
+ [.NET で Secrets Manager クライアント側のキャッシュを使用する方法](https://aws.amazon.com/blogs/security/how-to-use-aws-secrets-manager-client-side-caching-in-dotnet/) (AWS セキュリティブログ)