title: How to automatically add an autoscaled EC2 instance to a Security Group?
body: <p>I want to set up my AWS to autoscale EC2 instances (Windows Server 2012). The catch is that they need to have their IP addresses added to a Security Group so they can communicate with another EC2.</p>
  
  <ol>
  <li><p>Is there a way that AWS can handle this automatically through its autoscaling feature? (The closest I could find was to assign an IAM role to the new instances, but I don't I can add an IAM role to a Security Group, I can only add IP addresses.)</p></li>
  <li><p>The way I am currently looking into is to use the AWS CLI (command line) as a startup script.</p>
  
  <pre><code>ec2-authorize mySecurityGroup -p 1433 -s xx.xx.xx.xx/32
  </code></pre></li>
  </ol>
  
  <p>But how do I get the public IP of the current instance? Is there a AWS CLI command to get this? I'd rather not depend on an external website like "curl echoip.com". I heard about ec2-metadata, but I don't think that works for Windows, and I'd prefer not to use another third party software.</p>