ruby/example_code/ec2/ec2-ruby-example-security-group.rb
def create_security_group(
  ec2_client,
  group_name,
  description,
  vpc_id
)
  security_group = ec2_client.create_security_group(
    group_name: group_name,
    description: description,
    vpc_id: vpc_id
  )
  puts "Created security group '#{group_name}' with ID " \
    "'#{security_group.group_id}' in VPC with ID '#{vpc_id}'."
  return security_group.group_id
rescue StandardError => e
  puts "Error creating security group: #{e.message}"
  return 'Error'
end
# Creates an Amazon Elastic Compute Cloud (Amazon EC2) security group.
#
# Prerequisites:
#
# - A VPC in Amazon Virtual Private Cloud (Amazon VPC).
#
# @param ec2_client [Aws::EC2::Client] An initialized
#   Amazon EC2 client.
# @param group_name [String] A name for the security group.
# @param description [String] A description for the security group.
# @param vpc_id [String] The ID of the VPC for the security group.
# @return [String] The ID of security group that was created.
# @example
#   puts create_security_group(
#     Aws::EC2::Client.new(region: 'us-west-2'),
#     'my-security-group',
#     'This is my security group.',
#     'vpc-6713dfEX'
#   )

Creates an Amazon Elastic Compute Cloud (Amazon EC2) security group.
Prerequisites.

A VPC in Amazon Virtual Private Cloud (Amazon VPC).
Creates an Amazon Elastic Compute Cloud ( Amazon EC2 ) security group . Prerequisites . A VPC in Amazon Virtual Private Cloud ( Amazon VPC ) .
def create_security_group(
  ec2_client,
  group_name,
  description,
  vpc_id
)
  security_group = ec2_client.create_security_group(
    group_name: group_name,
    description: description,
    vpc_id: vpc_id
  )
  puts "Created security group '#{group_name}' with ID " \
    "'#{security_group.group_id}' in VPC with ID '#{vpc_id}'."
  return security_group.group_id
rescue StandardError => e
  puts "Error creating security group: #{e.message}"
  return 'Error'
end
def create_security_group ( ec2_client , group_name , description , vpc_id ) security_group = ec2_client . create_security_group ( group_name : group_name , description : description , vpc_id : vpc_id ) puts "Created security group '#{group_name}' with ID " "'#{security_group.group_id}' in VPC with ID '#{vpc_id}'." return security_group . group_id rescue StandardError => e puts "Error creating security group: #{e.message}" return 'Error' end
Creates an Amazon Elastic Compute Cloud (Amazon EC2) security group.
Creates an Amazon Elastic Compute Cloud ( Amazon EC2 ) security group .
The ID of security group that was created.
The ID of security group that was created .
String
ec2_client
An initialized Amazon EC2 client.
An initialized Amazon EC2 client .
group_name
A name for the security group.
A name for the security group .
description
A description for the security group.
A description for the security group .
vpc_id
The ID of the VPC for the security group.
The ID of the VPC for the security group .
example
puts create_security_group( Aws::EC2::Client.new(region: 'us-west-2'), 'my-security-group', 'This is my security group.', 'vpc-6713dfEX' )
puts create_security_group ( Aws :: EC2 :: Client . new ( region : ' us - west - 2 ' ) ' my - security - group ' ' This is my security group . ' ' vpc - 6713dfEX ' )