title: AWS CLI - Create script to add my IP to security group
body: <p>I'm trying to create a script to add my IP adress to AWS VPC security groups somthing like</p>
  <pre><code>&gt;  aws ec2 modify-security-group-rules --group-id GROUPID\
  &gt; --security-group-rules SecurityGroupRuleId= RULEID\
  SecurityGroupRule={IpProtocol:'tcp',FromPort:433,ToPort:433,CidrIpv4:'MYIP'}
  </code></pre>
  <p>But I keep getting different errors like -</p>
  <blockquote>
  <p>IpProtocol:tcp, type: &lt;class 'str'&gt;, valid types: &lt;class 'dict'&gt;</p>
  </blockquote>
  <p>Can anyone please help figure out the correct syntax for this?</p>
  <p>UPDATE:
  I tried a new syntax that seems to work better</p>
  <pre><code>SecurityGroupRule={{IpProtocol=tcp},{FromPort=433},{ToPort=433},{CidrIpv4='IP'}}
  </code></pre>
  <p>But now I get a different error from AWS -</p>
  <blockquote>
  <p>Invalid value for portRange. Must specify both from and to ports with TCP/UDP.</p>
  </blockquote>
  <p>UPDATE: For reference - Here's the workaround I used- (based on John Rotenstein answer)
  Instead of modifying the rule I create a new one each time and save the rule ID so I can delete it next time I run the script</p>
  <pre><code>IP=`curl -s http://whatismyip.akamai.com/`
  aws ec2 revoke-security-group-ingress \
           --group-id GROUP_ID         \
           --security-group-rule-ids $(cat ruleid_1.txt)
         
      aws ec2 authorize-security-group-ingress --group-id GROUP_ID\
  --ip-permissions &quot;IpProtocol&quot;=&quot;tcp&quot;,&quot;FromPort&quot;=433,&quot;ToPort&quot;=443,&quot;IpRanges&quot;=&quot;[{CidrIp=$IP/32,Description=Shalev}]&quot;|jq '.SecurityGroupRules[0].SecurityGroupRuleId' -r &gt; ruleid_1.txt
  </code></pre>