Skip to content

Instantly share code, notes, and snippets.

@chriskacerguis
Last active August 29, 2015 14:10
Show Gist options
  • Save chriskacerguis/368c7fd0e17e02ddf9c7 to your computer and use it in GitHub Desktop.
Save chriskacerguis/368c7fd0e17e02ddf9c7 to your computer and use it in GitHub Desktop.
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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment