どうも。森久です。
AWS の設定をする方法は2つあって、Web ブラウザから実施する方法と、awscli を使ってコマンドラインから実施する方法があります。
大量の設定をする場合や機械的に処理したい場合は、コマンドラインから実行する方法が圧倒的に簡単で楽です。
今回、awscli で AWS EC2 のロードバランサー(ALB)のルールを作成しようとしたところ、下記のエラーが出ました。
なお公式ドキュメント AWS CLI Command Reference の Example 2: To create a rule using a host condition and a fixed response を使って例示しています。
$ aws elbv2 create-rule \
> --listener-arn ルール作成対象リスナーのARN \
> --priority 10 \
> --conditions file://conditions-host.json \
> --actions file://actions-fixed-response.json
Parameter validation failed:
Unknown parameter in Conditions[0]: "HostHeaderConfig", must be one of: Field, Values
Unknown parameter in Actions[0]: "FixedResponseConfig", must be one of: Type, TargetGroupArn
この問題に3日ほど頭を悩ませましたが、やっと解決しました。。。
私が解決した方法
pip から最新版の awscli をインストールしたら解決しました。
下記のコマンドは、すでにインストールしている awscli をアップデートするコマンド例です。
$ python3 -m pip install --upgrade awscli
原因
Ubuntu の apt 経由でインストールした awscli コマンドのバージョンが古かったことが原因です。
失敗していたときの環境
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
$ aws --version
aws-cli/1.14.44 Python/3.6.9 Linux/5.3.0-1017-aws botocore/1.8.48
成功したときの環境
$ aws --version
aws-cli/1.18.56 Python/3.6.9 Linux/5.3.0-1017-aws botocore/1.16.6
$ aws elbv2 create-rule \
> --listener-arn ルール作成対象リスナーのARN \
> --priority 10 \
> --conditions file://conditions-host.json \
> --actions file://actions-fixed-response.json
{
"Rules": [
{
"RuleArn": "ルール作成対象リスナーのARN",
"Priority": "10",
"Conditions": [
{
"Field": "host-header",
"Values": [
"*.example.com"
],
"HostHeaderConfig": {
"Values": [
"*.example.com"
]
}
}
],
"Actions": [
{
"Type": "fixed-response",
"FixedResponseConfig": {
"MessageBody": "Hello world",
"StatusCode": "200",
"ContentType": "text/plain"
}
}
],
"IsDefault": false
}
]
}
結論
apt だけに頼っていてはいけない。