

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

# を使用した Amazon EC2 セキュリティグループとインスタンスタイプの設定 AWS CLI
<a name="using-features.managing.ec2.aws-cli"></a>

 AWS コマンドラインインターフェイス (AWS CLI) を使用して、Elastic Beanstalk 環境で Amazon EC2 インスタンスを設定できます。

## を使用した EC2 セキュリティグループの設定 AWS CLI
<a name="using-features.managing.ec2.aws-cli.security-groups"></a>

このトピックでは、単一インスタンス環境と負荷分散された (複数インスタンス) 環境の両方の異なる EC2 セキュリティグループ設定の例を提供します。これらの例のオプションの詳細については、「[aws:autoscaling:launchconfiguration](command-options-general.md#command-options-general-autoscalinglaunchconfiguration)」を参照してください。

**注意事項**  
環境の作成オペレーションは、デフォルトで EC2 セキュリティグループを提供します。また、デフォルトで Application Load Balancer を備えた環境を作成します。  
更新環境オペレーションは、ブール値オプション `DisableDefaultEC2SecurityGroup` を使用して、環境のデフォルトの EC2 セキュリティグループを無効または有効にするために使用できます。*例 5* は、以前に環境を変更したことがある場合に、環境をデフォルトのセキュリティ設定に戻す方法を示しています。

次の例は、デフォルトの EC2 セキュリティグループからオプトアウトし、代わりにカスタムセキュリティグループを提供する [create-environment](https://docs.aws.amazon.com/cli/latest/reference/elasticbeanstalk/create-environment.html) コマンドを示しています。`DisableDefaultEC2SecurityGroup` オプションは `true` に設定されているため、Elastic Beanstalk が通常 EC2 インスタンスに関連付けるデフォルトの EC2 セキュリティグループは作成されません。したがって、`SecurityGroups` オプションを他のセキュリティグループに提供する必要があります。

[aws:elasticbeanstalk:environment](command-options-general.md#command-options-general-elasticbeanstalkenvironment) `EnvironmentType` オプションは `SingleInstance` に設定されていることに注意してください。`LoadBalanced` はデフォルトの `EnvironmentType` であるため、単一のインスタンス環境を作成するには、このオプションを指定する必要があります。この環境にはロードバランサーが含まれていないため、ロードバランサーのセキュリティグループを指定する必要はありません。

**Example 1 — カスタム EC2 セキュリティグループを持つ新しい単一インスタンス環境 (インラインの名前空間オプション)**  

```
aws elasticbeanstalk create-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2023 v6.5.0 applrunning Node.js 22" \
--option-settings \
Namespace=aws:elasticbeanstalk:environment,OptionName=EnvironmentType,Value=SingleInstance \
Namespace=aws:autoscaling:launchconfiguration,OptionName=IamInstanceProfile,Value=aws-elasticbeanstalk-ec2-role \
Namespace=aws:autoscaling:launchconfiguration,OptionName=DisableDefaultEC2SecurityGroup,Value=true \
Namespace=aws:autoscaling:launchconfiguration,OptionName=SecurityGroups,Value=sg-abcdef01, sg-abcdef02 \
Namespace=aws:autoscaling:launchconfiguration,OptionName=EC2KeyName,Value=my-keypair
```





別の方法として、`options.json`ファイルを使用して、インラインで名前空間オプションを含めるのではなく、名前空間オプションを指定します。

**Example 2 — カスタム EC2 セキュリティグループを持つ新しい単一インスタンス環境 (`options.json` ファイルの名前空間オプション)**  

```
aws elasticbeanstalk create-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2023 v6.5.0 running Node.js 22" \
--option-settings file://options.json
```

**Example**  

```
### example options.json ###
[
  { "Namespace" : "aws:elasticbeanstalk:environment", 
    "OptionName" : "EnvironmentType", 
    "Value" : "SingleInstance" 
  },
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "IamInstanceProfile",
    "Value": "aws-elasticbeanstalk-ec2-role"
  },
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "DisableDefaultEC2SecurityGroup",
    "Value": "true"
  },
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "SecurityGroups",
    "Value": "sg-abcdef01, sg-abcdef02"
  },
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "EC2KeyName",
    "Value": "my-keypair"
  }
]
```

次の例では、負荷分散された環境を作成します。`application` に設定された [aws:elasticbeanstalk:environment](command-options-general.md#command-options-general-elasticbeanstalkenvironment) 名前空間オプション `LoadBalancerType` を指定します。`DisableDefaultEC2SecurityGroup` オプションを使用してデフォルトの EC2 セキュリティグループを無効にするため、前の例のように、[aws:autoscaling:launchconfiguration](command-options-general.md#command-options-general-autoscalinglaunchconfiguration) `SecurityGroups` オプションを使用して EC2 インスタンスに独自のカスタムセキュリティグループを再度指定する必要があります。この環境にはトラフィックをルーティングするロードバランサーがあるため、ロードバランサーのセキュリティグループも提供する必要があります。

Classic Load Balancer を使用し、それ以外は同じ設定の環境を作成するには、[aws:elasticbeanstalk:environment](command-options-general.md#command-options-general-elasticbeanstalkenvironment) 名前空間オプション `LoadBalancerType` の設定を `classic` に更新します。

異なるロードバランサーのタイプには、セキュリティグループを指定するオプションを保持する名前空間がそれぞれ異なって存在します。


+ Application Load Balancer – [aws:elbv2:loadbalancer](command-options-general.md#command-options-general-elbv2) `SecurityGroups` オプション
+ Classic Load Balancer – [aws:elb:loadbalancer](command-options-general.md#command-options-general-elbloadbalancer) `SecurityGroups` オプション
+ Network Load Balancer – Network Load Balancer にはセキュリティグループがないため、VPC 識別子を使用して EC2 セキュリティグループを設定します。詳細については、「*Network Load Balancers のユーザーガイド*」の「[Network Load Balancer のセキュリティグループを更新する](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/load-balancer-security-groups.html)」を参照してください。

**Example 3 — カスタム EC2 セキュリティグループを持つ新しいマルチインスタンス環境 (`options.json` ファイルの名前空間オプション)**  

```
aws elasticbeanstalk create-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2023 v6.5.0 running Node.js 22" \
--option-settings file://options.json
```

**Example**  

```
### example options.json ###
[
  { 
    "Namespace" : "aws:elasticbeanstalk:environment", 
    "OptionName" : "EnvironmentType", 
    "Value" : "LoadBalanced" 
  },
  { 
  "Namespace" : "aws:elasticbeanstalk:environment",
    "OptionName" : "LoadBalancerType",
    "Value" : "application"
  },
  {
    "Namespace" : "aws:elbv2:loadbalancer",
    "OptionName" : "SecurityGroups",
    "Value" : "sg-abcdefghikl012345"
  }, 
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "IamInstanceProfile",
    "Value": "aws-elasticbeanstalk-ec2-role"
  },
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "DisableDefaultEC2SecurityGroup",
    "Value": "true"
  },
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "SecurityGroups",
    "Value": "sg-abcdef01, sg-abcdef02"
  },
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "EC2KeyName",
    "Value": "my-keypair"
  }
]
```

[update-environment](https://docs.aws.amazon.com/cli/latest/reference/elasticbeanstalk/update-environment.html) コマンドを使用して、既存の環境のデフォルトの EC2 セキュリティグループを無効にすることができます。次のコマンド例では、デフォルトの EC2 セキュリティグループを無効にし、環境の EC2 インスタンスでカスタム EC2 セキュリティグループを割り当てます。

環境がロードバランシングされているかどうかとロードバランサーのタイプに応じて、例 4 (a)、4 (b)、または 4 (c) の `options.jason` ファイルの例を使用します。設定ファイル 4 (a) は、単一インスタンス環境のセキュリティグループを指定します。ロードバランサーを必要としないため、EC2 インスタンスのセキュリティグループのみが提供されます。設定ファイル 4 (b) と 4 (c) は、Application Load Balancer と Classic Load Balancer のセキュリティグループを指定します。このような場合は、ロードバランサーのセキュリティグループも指定する必要があります。

**Example 4 — 既存の環境を更新してデフォルトの EC2 セキュリティグループを無効にする (`options.json` ファイルの名前空間オプション)**  

```
aws elasticbeanstalk update-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2023 v6.5.0 running Node.js 22" \
--option-settings file://options.json
```

**Example 4 (a) — 単一インスタンス環境の設定ファイル (ロードバランサーなし)**  

```
### example options.json ###
[
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "DisableDefaultEC2SecurityGroup",
    "Value": "true"
  },
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "SecurityGroups",
    "Value": "sg-abcdef01, sg-abcdef02"
  }
]
```

Application Load Balancer を使用している環境を更新するには、`aws:elbv2:loadbalancer` 名前空間を使用してロードバランサーのセキュリティグループを指定します。

**Example 4 (b) — Application Load Balancer を使用する環境の設定ファイル**  

```
### example options.json ###
[
  {
    "Namespace" : "aws:elbv2:loadbalancer",
    "OptionName" : "SecurityGroups",
    "Value" : "sg-abcdefghikl012345"
  }, 
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "DisableDefaultEC2SecurityGroup",
    "Value": "true"
  },
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "SecurityGroups",
    "Value": "sg-abcdef01, sg-abcdef02"
  }
]
```

Classic Load Balancer を使用していする環境を更新するには、`aws:elb:loadbalancer` 名前空間を使用してロードバランサーのセキュリティグループを指定します。

**Example 4 (c) — Classic Load Balancer を使用する環境の設定ファイル**  

```
### example options.json ###
[
  {
    "Namespace" : "aws:elb:loadbalancer",
    "OptionName" : "SecurityGroups",
    "Value" : "sg-abcdefghikl012345"
  }, 
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "DisableDefaultEC2SecurityGroup",
    "Value": "true"
  },
  {
    "Namespace": "aws:autoscaling:launchconfiguration",n
    "OptionName": "SecurityGroups",
    "Value": "sg-abcdef01, sg-abcdef02"
  }
]
```

Elastic Beanstalk が割り当てるデフォルトのセキュリティグループを使用して環境をデフォルトの動作と設定に戻すには、[update-environment](https://docs.aws.amazon.com/cli/latest/reference/elasticbeanstalk/update-environment.html) コマンドを使用して `DisableDefaultEC2SecurityGroup` を `false` に設定します。マルチインスタンス環境の場合、Elastic Beanstalk は環境のロードバランサーのセキュリティグループとネットワークトラフィックルールも処理します。

次の例は、単一インスタンス環境またはマルチインスタンス (負荷分散された) 環境の両方に適用されます。

**Example 5 — デフォルトのセキュリティグループを使用して環境を更新し直す (`options.json` ファイルの名前空間オプション)**  

```
aws elasticbeanstalk update-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2023 v6.5.0 running Node.js 22" \
--option-settings file://options.json
```

**Example**  

```
### example options.json ###
[
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "DisableDefaultEC2SecurityGroup",
    "Value": "false"
  }
]
```

## を使用してインスタンスタイプで EC2 を設定する AWS CLI
<a name="using-features.managing.ec2.aws-cli.instance-types"></a>

このトピックでは、環境内の EC2 インスタンスのインスタンスタイプを設定するための例を提供します。

最初の 2 つの例では、新しい環境を作成します。このコマンドは、arm64 プロセッサアーキテクチャに基づく Amazon EC2 インスタンスタイプ t4g.small を指定します。Elastic Beanstalk は、リージョン、プラットフォームのバージョン、インスタンスタイプに基づいて EC2 インスタンスのイメージ ID（AMI）をデフォルト設定します。インスタンスタイプは、プロセッサアーキテクチャに対応します。-`solution-stack-name`パラメータはプラットフォームバージョンに適用されます。

**Example 1 — 新しい arm64 ベースの環境を作成する (名前空間オプションをインライン)**  

```
aws elasticbeanstalk create-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2 v3.4.7 running Docker" \
--option-settings \
Namespace=aws:autoscaling:launchconfiguration,OptionName=IamInstanceProfile,Value=aws-elasticbeanstalk-ec2-role \
Namespace=aws:ec2:instances,OptionName=InstanceTypes,Value=t4g.small
```



別の方法として、`options.json`ファイルを使用して、インラインで名前空間オプションを含めるのではなく、名前空間オプションを指定します。

**Example 2 — 新しい arm64 ベースの環境 (名前空間オプション) を作成します。`options.json`ファイル)**  

```
aws elasticbeanstalk create-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2 v3.4.7 running Docker" \
--option-settings file://options.json
```

**Example**  

```
### example options.json ###
[
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "IamInstanceProfile",
    "Value": "aws-elasticbeanstalk-ec2-role"
  },
  {
    "Namespace": "aws:ec2:instances",
    "OptionName": "InstanceTypes",
    "Value": "t4g.small"
  }
]
```





次の 2 つの例では、既存の環境の設定を[update-environment](https://docs.aws.amazon.com/cli/latest/reference/elasticbeanstalk/update-environment.html)コマンド。この例では、arm64 プロセッサアーキテクチャに基づく別のインスタンスタイプを追加します。既存の環境では、追加されるすべてのインスタンスタイプが同じプロセッサアーキテクチャを持つ必要があります。既存のインスタンスタイプを別のアーキテクチャのインスタンスタイプに置き換えることもできます。ただし、コマンド内のすべてのインスタンスタイプが同じタイプのアーキテクチャであることを確認します。

**Example 3 — 既存の arm64 ベースの環境を更新する (名前空間オプションをインライン)**  

```
aws elasticbeanstalk update-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2 v3.4.7 running Docker" \
--option-settings \
Namespace=aws:autoscaling:launchconfiguration,OptionName=IamInstanceProfile,Value=aws-elasticbeanstalk-ec2-role \
Namespace=aws:ec2:instances,OptionName=InstanceTypes,Value=t4g.small,t4g.micro
```



別の方法として、`options.json`ファイルを使用して、インラインで名前空間オプションを含めるのではなく、名前空間オプションを指定します。

**Example 4 — 既存の arm64 ベースの環境を更新する (名前空間オプション)`options.json`ファイル)**  

```
aws elasticbeanstalk update-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2 v3.4.7 running Docker" \
--option-settings file://options.json
```

**Example**  

```
### example options.json ###
[
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "IamInstanceProfile",
    "Value": "aws-elasticbeanstalk-ec2-role"
  },
  {
    "Namespace": "aws:ec2:instances",
    "OptionName": "InstanceTypes",
    "Value": "t4g.small, t4g.micro"
  }
]
```





次の 2 つの例で詳しく説明します。[環境を作成する](https://docs.aws.amazon.com/cli/latest/reference/elasticbeanstalk/create-environment.html)コマンド。これらの例は、の値を提供しません。`InstanceTypes`。メトリック`InstanceTypes`値は指定されていません。Elastic Beanstalk はデフォルトで x86 ベースのプロセッサアーキテクチャです。環境の EC2 インスタンスのイメージ ID（AMI）は、リージョン、プラットフォームのバージョン、およびデフォルトのインスタンスタイプに従ってデフォルト設定されます。インスタンスタイプは、プロセッサアーキテクチャに対応します。

**Example 5 — 新しい x86 ベースの環境を作成する (名前空間オプションをインライン)**  

```
aws elasticbeanstalk create-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2 v3.4.7 running Docker" \
--option-settings \
Namespace=aws:autoscaling:launchconfiguration,OptionName=IamInstanceProfile,Value=aws-elasticbeanstalk-ec2-role
```



別の方法として、`options.json`ファイルを使用して、インラインで名前空間オプションを含めるのではなく、名前空間オプションを指定します。

**Example 6 — 新しい x86 ベースの環境 (名前空間オプション) を作成します。`options.json`ファイル)**  

```
aws elasticbeanstalk create-environment \
--region us-east-1 \
--application-name my-app \
--environment-name my-env \
--solution-stack-name "64bit Amazon Linux 2 v3.4.7 running Docker" \
--option-settings file://options.json
```

**Example**  

```
### example options.json ###
[
  {
    "Namespace": "aws:autoscaling:launchconfiguration",
    "OptionName": "IamInstanceProfile",
    "Value": "aws-elasticbeanstalk-ec2-role"
  }
]
```