chriskacerguis
11/25/2014 - 7:02 PM

Create a security group in AWS via Ruby AWS SDK

Create a security group in AWS via Ruby AWS SDK

# Written by Chris Kacerguis
# AWS Credentials
ec2 = AWS::EC2.new(
  :access_key_id => 'YOUR_ACCESS_KEY_ID',
  :secret_access_key => 'YOUR_SECRET_ACCESS_KEY')

secgrp = ec2.security_groups.create('NAME_OF_SECURITY_GROUP')

# EXAMPLE: single port
secgrp.authorize_ingress(:tcp, 80)

# EXAMPLE: port range
secgrp.authorize_ingress(:tcp, 0..65000)

# EXAMPLE: single port with specific IPs
secgrp.authorize_ingress(:tcp, 22, '1.1.1.1/0', '2.2.2.2/0')