

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 建立安全群組以支援 EFA 通訊
<a name="working-with_networking_efa_create-sg"></a>

------
#### [ AWS CLI ]

您可以使用下列 AWS CLI 命令來建立支援 EFA 的安全群組。命令會輸出安全群組 ID。進行下列取代：
+ `region-code` – 指定您使用 AWS PCS 的 AWS 區域 ，例如 `us-east-1`。
+ `vpc-id` – 指定您用於 AWS PCS 的 VPC ID。
+ `efa-group-name` – 為安全群組提供您選擇的名稱。

```
aws ec2 create-security-group \
    --group-name efa-group-name \
    --description "Security group to enable EFA traffic" \
    --vpc-id vpc-id \
    --region region-code
```

使用下列命令來連接傳入和傳出安全群組規則。進行下列取代：
+ `efa-secgroup-id` – 提供您剛建立的 EFA 安全群組 ID。

```
aws ec2 authorize-security-group-ingress \
    --group-id efa-secgroup-id \
    --protocol -1 \
    --source-group efa-secgroup-id
    
aws ec2 authorize-security-group-egress \
    --group-id efa-secgroup-id \
    --protocol -1 \
    --source-group efa-secgroup-id
```

------
#### [ CloudFormation template ]

您可以使用 CloudFormation 範本來建立支援 EFA 的安全群組。從下列 URL 下載範本，然後將其上傳至 [AWS CloudFormation 主控台](https://console.aws.amazon.com/cloudformation)。

```
https://aws-hpc-recipes.s3.amazonaws.com/main/recipes/pcs/enable_efa/assets/efa-sg.yaml
```

在 AWS CloudFormation 主控台中開啟範本時，輸入下列選項。
+ 在**提供堆疊名稱**下
  + 在**堆疊名稱**下，輸入名稱，例如 `efa-sg-stack`。
+ 在**參數**下
  + 在 **SecurityGroupName** 下，輸入名稱，例如 `efa-sg`。
  + 在 **VPC** 下，選取您將使用 AWS PCS 的 VPC。

完成建立 CloudFormation 堆疊並監控其狀態。當它到達 EFA `CREATE_COMPLETE` 安全群組時，即可使用。

------