

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

# Managed Service for Apache Flink のランタイムプロパティを使用する
<a name="how-properties"></a>

「*ランタイムプロパティ*」を使用すると、アプリケーションコードを再コンパイルせずにアプリケーションを設定できます。

**Topics**
+ [コンソールを使用してランタイムプロパティを管理する](#how-properties-console)
+ [CLI を使用してランタイムプロパティを管理する](#how-properties-cli)
+ [Managed Service for Apache Flink アプリケーションのランタイムプロパティにアクセスする](#how-properties-access)

## コンソールを使用してランタイムプロパティを管理する
<a name="how-properties-console"></a>

 AWS マネジメントコンソールを使用して Managed Service for Apache Flink アプリケーションのランタイムプロパティを追加、更新、または削除できます。

**注記**  
過去にサポートされていたバージョンの Apache Flink を使用していて、既存のアプリケーションを Apache Flink 1.19.1 にアップグレードする場合は、インプレースの Apache Flink バージョンアップグレードを使用してアップグレードできます。インプレースのバージョンアップグレードでは、スナップショット、ログ、メトリクス、タグ、Flink 設定など、Apache Flink バージョン全体で、単一の ARN に対するアプリケーションのトレーサビリティを保持します。この機能は、`RUNNING` および `READY` 状態で使用できます。詳細については、「[Apache Flink のインプレースバージョンアップグレードを使用する](how-in-place-version-upgrades.md)」を参照してください。

**Apache Flink アプリケーション用 Managed Serviceのランタイムプロパティの更新**

1. にサインインし AWS マネジメントコンソール、https://console.aws.amazon.com/flink で Amazon MSF コンソールを開きます。

1. Apache Flink アプリケーション用 Managed Serviceを選択します。[**Application details (アプリケーションの詳細)**] を選択します。

1. アプリケーションのページで、**構成** をクリックします。

1. 「**プロパティ**」セクションを展開します。

1. 「**プロパティ‭**」セクションのコントロールを使用して、キーと値のペアを含むプロパティグループを定義します。これらのコントロールを使用して、プロパティグループとランタイムプロパティを追加、更新、削除します。

1. **[更新]** を選択します。

## CLI を使用してランタイムプロパティを管理する
<a name="how-properties-cli"></a>

「[AWS CLI](https://docs.aws.amazon.com/cli)」を使用してランタイムプロパティを追加、更新、削除できます。

このセクションには、アプリケーションのランタイムプロパティを設定するための API アクションのリクエスト例が含まれています。JSON ファイルを API アクションの入力に使用する方法の詳細については、[Managed Service for Apache Flink API コードの例](api-examples.md)　を参照してください。

**注記**  
次の例のサンプルのアカウント ID (*`012345678901`*) をアカウント ID に置き換えます。

### アプリケーション作成時にランタイムプロパティを追加する
<a name="how-properties-create"></a>

以下の「[https://docs.aws.amazon.com/managed-service-for-apache-flink/latest/apiv2/API_CreateApplication.html](https://docs.aws.amazon.com/managed-service-for-apache-flink/latest/apiv2/API_CreateApplication.html)」アクションリクエスト例では、アプリケーションの作成時に 2 つのランタイムプロパティグループ (`ProducerConfigProperties` と `ConsumerConfigProperties`) を追加します。

```
{
    "ApplicationName": "MyApplication",
    "ApplicationDescription": "my java test app",
    "RuntimeEnvironment": "FLINK-1_19",
    "ServiceExecutionRole": "arn:aws:iam::012345678901:role/MF-stream-rw-role",
    "ApplicationConfiguration": {
        "ApplicationCodeConfiguration": {
            "CodeContent": {
                "S3ContentLocation": {
                    "BucketARN": "arn:aws:s3:::ka-app-code-username",
                    "FileKey": "java-getting-started-1.0.jar"
                }
            },
            "CodeContentType": "ZIPFILE"
        },
        "EnvironmentProperties":  { 
         "PropertyGroups": [ 
            { 
               "PropertyGroupId": "ProducerConfigProperties",
               "PropertyMap" : {
                    "flink.stream.initpos" : "LATEST",
                    "aws.region" : "us-west-2",
                    "AggregationEnabled" : "false"
               }
            },
            { 
               "PropertyGroupId": "ConsumerConfigProperties",
               "PropertyMap" : {
                    "aws.region" : "us-west-2"
               }
            }
         ]
      }
    }
}
```

### 既存のアプリケーションのランタイムプロパティを追加および更新する
<a name="how-properties-update"></a>

以下の「[https://docs.aws.amazon.com/managed-service-for-apache-flink/latest/apiv2/API_UpdateApplication.html](https://docs.aws.amazon.com/managed-service-for-apache-flink/latest/apiv2/API_UpdateApplication.html)」アクションリクエスト例は、既存のアプリケーションのランタイムプロパティを追加または更新します。

```
{
  "ApplicationName": "MyApplication",
  "CurrentApplicationVersionId": 2,
  "ApplicationConfigurationUpdate": {
    "EnvironmentPropertyUpdates": {
      "PropertyGroups": [ 
        { 
          "PropertyGroupId": "ProducerConfigProperties",
          "PropertyMap" : {
            "flink.stream.initpos" : "LATEST",
            "aws.region" : "us-west-2",
            "AggregationEnabled" : "false"
          }
        },
        { 
          "PropertyGroupId": "ConsumerConfigProperties",
          "PropertyMap" : {
            "aws.region" : "us-west-2"
          }
        }
      ]
    }
  }
}
```

**注記**  
プロパティグループに対応するランタイムプロパティがないキーを使用すると、Apache Flink 用 Managed Service はそのキーと値のペアを新しいプロパティとして追加します。プロパティグループ内の既存のランタイムプロパティのキーを使用すると、Apache Flink 用 Managed Service はそのプロパティ値を更新します。

### ランタイムプロパティを削除する
<a name="how-properties-remove"></a>

以下の「[https://docs.aws.amazon.com/managed-service-for-apache-flink/latest/apiv2/API_UpdateApplication.html](https://docs.aws.amazon.com/managed-service-for-apache-flink/latest/apiv2/API_UpdateApplication.html)」アクションリクエスト例では、既存のアプリケーションからすべてのランタイムプロパティとプロパティグループを削除します。

```
{
  "ApplicationName": "MyApplication",
  "CurrentApplicationVersionId": 3,
  "ApplicationConfigurationUpdate": {
    "EnvironmentPropertyUpdates": {
      "PropertyGroups": []
    }
  }
}
```

**重要**  
既存のプロパティグループまたはプロパティグループ内の既存のプロパティキーを省略すると、そのプロパティグループまたはプロパティは削除されます。

## Managed Service for Apache Flink アプリケーションのランタイムプロパティにアクセスする
<a name="how-properties-access"></a>

Java アプリケーションコード内のランタイムプロパティは、`Map<String, Properties>` オブジェクトを返す静的 `KinesisAnalyticsRuntime.getApplicationProperties()` メソッドを使用して取得します。

次の Java コードの例では、アプリケーションのランタイムプロパティを取得します。

```
 Map<String, Properties> applicationProperties = KinesisAnalyticsRuntime.getApplicationProperties();
```

プロパティグループを (`Java.Util.Properties` オブジェクトとして) 次のように取得します。

```
Properties consumerProperties = applicationProperties.get("ConsumerConfigProperties");
```

Apache Flink のソースまたはシンクは、通常、個々のプロパティを取得せずに `Properties` オブジェクトを渡すことで設定します。以下のコード例は、ランタイムプロパティから取得した `Properties` オブジェクトを渡して Flink ソースを作成する方法を示しています。

```
private static FlinkKinesisProducer<String> createSinkFromApplicationProperties() throws IOException {
  Map<String, Properties> applicationProperties = KinesisAnalyticsRuntime.getApplicationProperties();
  FlinkKinesisProducer<String> sink = new FlinkKinesisProducer<String>(new SimpleStringSchema(),
    applicationProperties.get("ProducerConfigProperties"));

  sink.setDefaultStream(outputStreamName);
  sink.setDefaultPartition("0");
  return sink;
}
```

コード例については、[Managed Service for Apache Flink アプリケーションの作成と操作の例](examples-collapsibles.md) を参照してください。