

# 使用 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
```