

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 [AWS](https://github.com/awsdocs/aws-doc-sdk-examples)

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

# CLI で `SetSecurityGroups` を使用する
<a name="elastic-load-balancing-v2_example_elastic-load-balancing-v2_SetSecurityGroups_section"></a>

次のサンプルコードは、`SetSecurityGroups` を使用する方法を説明しています。

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

**AWS CLI**  
**セキュリティグループをロードバランサーに関連付けるには**  
この例では、指定されたセキュリティグループを指定されたロードバランサーに関連付けます。  
コマンド:  

```
aws elbv2 set-security-groups --load-balancer-arn {{arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188}} --security-groups {{sg-5943793c}}
```
出力:  

```
{
  "SecurityGroupIds": [
      "sg-5943793c"
  ]
}
```
+  API の詳細については、「*AWS CLI コマンドリファレンス*」の「[SetSecurityGroups](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/elbv2/set-security-groups.html)」を参照してください。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**例 1: この例では、セキュリティグループ「sg-07c3414abb8811cbd」を指定されたロードバランサーに追加します。**  

```
Set-ELB2SecurityGroup -LoadBalancerArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/test-alb/3651b4394dd9a24f' -SecurityGroup 'sg-07c3414abb8811cbd'
```
**出力:**  

```
sg-07c3414abb8811cbd
```
+  API の詳細については、「*AWS Tools for PowerShell コマンドレットリファレンス (V4)*」の「[SetSecurityGroups](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

**Tools for PowerShell V5**  
**例 1: この例では、セキュリティグループ「sg-07c3414abb8811cbd」を指定されたロードバランサーに追加します。**  

```
Set-ELB2SecurityGroup -LoadBalancerArn 'arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/test-alb/3651b4394dd9a24f' -SecurityGroup 'sg-07c3414abb8811cbd'
```
**出力:**  

```
sg-07c3414abb8811cbd
```
+  API の詳細については、「*AWS Tools for PowerShell コマンドレットリファレンス (V5)*」の「[SetSecurityGroups](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

------