ruby/example_code/ec2/ec2-ruby-example-security-group.rb
def describe_security_group_permissions(perm)
  print "  Protocol: #{perm.ip_protocol == '-1' ? 'All' : perm.ip_protocol}"

  unless perm.from_port.nil?
    if perm.from_port == '-1' || perm.from_port == -1
      print ', From: All'
    else
      print ", From: #{perm.from_port}"
    end
  end

  unless perm.to_port.nil?
    if perm.to_port == '-1' || perm.to_port == -1
      print ', To: All'
    else
      print ", To: #{perm.to_port}"
    end
  end

  if perm.key?(:ipv_6_ranges) && perm.ipv_6_ranges.count.positive?
    print ", CIDR IPv6: #{perm.ipv_6_ranges[0].cidr_ipv_6}"
  end

  if perm.key?(:ip_ranges) && perm.ip_ranges.count.positive?
    print ", CIDR IPv4: #{perm.ip_ranges[0].cidr_ip}"
  end

  print "\n"
end
# Displays information about a security group's IP permissions set in
# Amazon Elastic Compute Cloud (Amazon EC2).
#
# Prerequisites:
#
# - A security group with inbound rules, outbound rules, or both.
#
# @param p [Aws::EC2::Types::IpPermission] The IP permissions set.
# @example
#   ec2_client = Aws::EC2::Client.new(region: 'us-west-2')
#   response = ec2_client.describe_security_groups
#   unless sg.ip_permissions.empty?
#     describe_security_group_permissions(
#       response.security_groups[0].ip_permissions[0]
#     )
#   end

Displays information about a security group's IP permissions set in
Amazon Elastic Compute Cloud (Amazon EC2).



A security group with inbound rules, outbound rules, or both.
Displays information about a security group ' s IP permissions set in Amazon Elastic Compute Cloud ( Amazon EC2 ) . A security group with inbound rules outbound rules or both .
def describe_security_group_permissions(perm)
  print "  Protocol: #{perm.ip_protocol == '-1' ? 'All' : perm.ip_protocol}"
  unless perm.from_port.nil?
    if perm.from_port == '-1' || perm.from_port == -1
      print ', From: All'
    else
      print ", From: #{perm.from_port}"
    end
  end
  unless perm.to_port.nil?
    if perm.to_port == '-1' || perm.to_port == -1
      print ', To: All'
    else
      print ", To: #{perm.to_port}"
    end
  end
  if perm.key?(:ipv_6_ranges) && perm.ipv_6_ranges.count.positive?
    print ", CIDR IPv6: #{perm.ipv_6_ranges[0].cidr_ipv_6}"
  end
  if perm.key?(:ip_ranges) && perm.ip_ranges.count.positive?
    print ", CIDR IPv4: #{perm.ip_ranges[0].cidr_ip}"
  end
  print "\n"
end
def describe_security_group_permissions ( perm ) print "  Protocol: #{perm.ip_protocol == '-1' ? 'All' : perm.ip_protocol}" unless perm . from_port . nil? if perm . from_port == '-1' || perm . from_port == - 1 print ', From: All' else print ", From: #{perm.from_port}" end end unless perm . to_port . nil? if perm . to_port == '-1' || perm . to_port == - 1 print ', To: All' else print ", To: #{perm.to_port}" end end if perm . key? ( :ipv_6_ranges ) && perm . ipv_6_ranges . count . positive? print ", CIDR IPv6: #{perm.ipv_6_ranges[0].cidr_ipv_6}" end if perm . key? ( :ip_ranges ) && perm . ip_ranges . count . positive? print ", CIDR IPv4: #{perm.ip_ranges[0].cidr_ip}" end print "\n" end
Displays information about a security group's IP permissions set in
Amazon Elastic Compute Cloud (Amazon EC2).
Displays information about a security group ' s IP permissions set in Amazon Elastic Compute Cloud ( Amazon EC2 ) .
perm
p
The IP permissions set.
The IP permissions set .
example
ec2_client = Aws::EC2::Client.new(region: 'us-west-2') response = ec2_client.describe_security_groups unless sg.ip_permissions.empty. describe_security_group_permissions( response.security_groups[0].ip_permissions[0] ) end
ec2_client = Aws :: EC2 :: Client . new ( region : ' us - west - 2 ' ) response = ec2_client . describe_security_groups unless sg . ip_permissions . empty . describe_security_group_permissions ( response . security_groups [ 0 ] . ip_permissions [ 0 ] ) end