Creating an Amazon EC2 Security Group - AWS SDK for Ruby

Creating an Amazon EC2 Security Group

The following example creates a security group named MyGroovySecurityGroup in the us-west-2 region on a VPC with the ID VPC_ID. In the example, the security group is allowed access over port 22 (SSH) from all addresses (CIDR block, and is given the description “Security group for MyGroovyInstance”. Then, the security group’s ID is displayed.

require 'aws-sdk-ec2' # v2: require 'aws-sdk' ec2 = 'us-west-2') sg = ec2.create_security_group({ group_name: 'MyGroovySecurityGroup', description: 'Security group for MyGroovyInstance', vpc_id: 'VPC_ID' }) sg.authorize_egress({ ip_permissions: [{ ip_protocol: 'tcp', from_port: 22, to_port: 22, ip_ranges: [{ cidr_ip: '' }] }] }) puts