aws cliでセキュリティグループにICMPのルールを追加するとき、FromPort、ToPortには0、65535でも指定しておけば良いのかなと思ったらエラーになった。
$ aws ec2 authorize-security-group-ingress --group-id sg-xxxxxxxx --ip-permissions IpProtocol=icmp,FromPort=0,ToPort=65535,IpRanges='[{CidrIp=999.999.999.999/32,Description="Example"}]'
An error occurred (InvalidParameterValue) when calling the AuthorizeSecurityGroupIngress operation: ICMP code (65535) out of range
0、0にしたらエラーにはならなかったけど、プロトコルがエコー応答として登録された。プロトコルはすべてで登録したい。
調べてみたところ、ICMPのルールを追加するときのFromPort、ToPortにはICMP codeを指定するらしい。
authorize-security-group-ingress — AWS CLI 1.16.311 Command Reference
0はエコー応答なのね。
Internet Control Message Protocol - Wikipedia
すべてを指定したい時は−1を指定すれば良いようなので、FromPort、ToPortに−1を指定したら、プロトコル:すべてで無事登録された。
$ aws ec2 authorize-security-group-ingress --group-id sg-xxxxxxxx --ip-permissions IpProtocol=icmp,FromPort=-1,ToPort=-1,IpRanges='[{CidrIp=999.999.999.999/32,Description="Example"}]'
大量のIP許可設定とかやる時はCLIがやっぱり便利。