LoginSignup
0
0

An error occurred (InvalidPermission.Duplicate) when calling the AuthorizeSecurityGroupIngress operation

Posted at

Github action を利用して、EC2サーバにログインすると、Security Group 重複のため、下記のエラーが出てしまう。

            aws ec2 authorize-security-group-ingress \
            --group-id='sg-xxxxxxx' \
            --protocol=tcp \
            --port=22 \
            --cidr=xxx.xxx.xxx.xxx/32
An error occurred (InvalidPermission.Duplicate) when calling the AuthorizeSecurityGroupIngress operation: the specified rule "peer: xxx.xxx.xxx.xxx/32, TCP, from port: ***, to port: ***, ALLOW" already exists
Error: Process completed with exit code 254.

image.png

Security Group 重複回避方法

          set +e # Disable immediate exit on error
          aws ec2 authorize-security-group-ingress \
          --group-id='sg-xxxxxxx' \
          --protocol=tcp \
          --port=22 \
          --cidr=xxx.xxx.xxx.xxx/32
          # avoid the InvalidPermission.Duplicate error
          if [ $? -eq 254 ]; then
            echo "Rule already exists."
          fi
          set -e # Re-enable immediate exit on error
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0