

# AWS CloudFormation を使用した Aurora DSQL クラスターの設定
<a name="mr-cluster-setup"></a>

 同じ CloudFormation リソース `AWS::DSQL::Cluster` を使用して、単一リージョンおよびマルチリージョンの Aurora DSQL クラスターをデプロイおよび管理できます。

`AWS::DSQL::Cluster` リソースを使用して、クラスターを作成、変更、管理する方法については、「[Amazon Aurora DSQL resource type reference](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/AWS_DSQL.html)」を参照してください。

## 初期クラスター設定の作成
<a name="mr-cluster-initial"></a>

まず、マルチリージョンクラスターを定義する AWS CloudFormation テンプレートを作成します。

```
---
Resources:
  MRCluster:
    Type: AWS::DSQL::Cluster
    Properties:
      DeletionProtectionEnabled: true
      MultiRegionProperties:
        WitnessRegion: us-west-2
```

次の AWS CLI コマンドを使用して、両方のリージョンにスタックを作成します。

```
aws cloudformation create-stack --region us-east-2 \
    --stack-name MRCluster \
    --template-body file://mr-cluster.yaml
```

```
aws cloudformation create-stack --region us-east-1 \
    --stack-name MRCluster \
    --template-body file://mr-cluster.yaml
```

## クラスター識別子の検索
<a name="mr-cluster-find"></a>

クラスターの物理リソース ID を取得します。

```
aws cloudformation describe-stack-resources -region us-east-2 \
    --stack-name MRCluster \
    --query 'StackResources[].PhysicalResourceId'
[
  "auabudrks5jwh4mjt6o5xxhr4y"
]
```

```
aws cloudformation describe-stack-resources -region us-east-1 \
    --stack-name MRCluster \
    --query 'StackResources[].PhysicalResourceId'
[
  "imabudrfon4p2z3nv2jo4rlajm"
]
```

## クラスター設定の更新
<a name="mr-cluster-update"></a>

AWS CloudFormation テンプレートを更新して、以下の両方のクラスター ARN を含めます。

```
---
Resources:
  MRCluster:
    Type: AWS::DSQL::Cluster
    Properties:
      DeletionProtectionEnabled: true
      MultiRegionProperties:
        WitnessRegion: us-west-2
        Clusters:
        - arn:aws:dsql:us-east-2:123456789012:cluster/auabudrks5jwh4mjt6o5xxhr4y
        - arn:aws:dsql:us-east-1:123456789012:cluster/imabudrfon4p2z3nv2jo4rlajm
```

更新した設定を両方のリージョンに適用します。

```
aws cloudformation update-stack --region us-east-2 \
    --stack-name MRCluster \
    --template-body file://mr-cluster.yaml
```

```
aws cloudformation update-stack --region us-east-1 \
    --stack-name MRCluster \
    --template-body file://mr-cluster.yaml
```