user3299633
user3299633

Reputation: 3390

Updating long list of IP descriptions with AWS CLI

I'm running into quoting issues with AWS CLI when trying to update description of security group rules.

Can anyone advise how I can rewrite this piece to accommodate a list of IPs?

while read -r line; do
  aws ec2 update-security-group-rule-descriptions-ingress \
      --group-id sg-123456 \
      --region us-east-2 \
      --ip-permissions "[{'IpProtocol': 'tcp', 'FromPort': 443, 'ToPort': 443, 'IpRanges': [{'CidrIp': ${line}, 'Description': 'Meaningful description'}]}]"
done < ip_list

Upvotes: 0

Views: 75

Answers (2)

user3299633
user3299633

Reputation: 3390

I ended up having to use this format:

while IFS=, read -r IP CLIENT_DESC
do
   aws ec2 authorize-security-group-ingress --region us-east-2 --group-id sg-123456 --ip-permissions IpProtocol=tcp,FromPort=443,ToPort=443,IpRanges="[{CidrIp=${IP},Description=${CLIENT_DESC}}]"
done < server_rules

Upvotes: 0

peter n
peter n

Reputation: 1290

Move the single quotes to encompass the whole JSON, then use double quotes for the JSON content, which typically expects double quotes.

--ip-permissions '[{"IpProtocol": "tcp", "FromPort": 443, "ToPort": 443, "IpRanges": [{"CidrIp": ${line}, "Description": "Meaningful description"}]}]'

Upvotes: 1

Related Questions