I have a list of IP addresses. I want to allow `tcp/22` traffic from them and block any other IP address. The list is long and contains about 50-60 IP addresses. How can I add this to a Security Group without manually adding them one by one.

Thankyou!

Solution:

I found a way using `aws` cli

For allowing SSH to a range of cidrs

```
bash# for ip in {csv_list_of_cidrs}
> do
> aws ec2 authorize-security-group-ingress --group-id <sg_ig_here> --protocol tcp --port 22 --cidr $ip
> done

```

eg:

```
for ip in {1.1.1.1/8,2.2.2.2/16,3.2.3.12/29}
do
aws ec2 authorize-security-group-ingress --group-id sg-xxxxxxxxx --protocol tcp --port 22 --cidr $ip
done

```

For solution using`boto3` refer to the answer below