Scalr\Service\Aws\Ec2\V20140615\Ec2Api::authorizeSecurityGroupIngress PHP Method

authorizeSecurityGroupIngress() public method

Adds one or more ingress rules to a security group. This action applies to both EC2 security groups and VPC security groups. For EC2 security groups, this action gives one or more CIDR IP address ranges permission to access a security group in your account, or gives one or more security groups (called the source groups) permission to access a security group in your account. A source group can be in your own AWS account, or another. For VPC security groups, this action gives one or more CIDR IP address ranges permission to access a security group in your VPC, or gives one or more other security groups (called the source groups) permission to access a security group in your VPC. The groups must all be in the same VPC. Each rule consists of the protocol (e.g., TCP), plus either a CIDR range or a source group. For the TCP and UDP protocols, you must also specify the destination port or port range. For the ICMP protocol, you must also specify the ICMP type and code.You can use -1 for the type or code to mean all types or all codes. Rule changes are propagated to instances within the security group as quickly as possible. However, a small delay might occur.
public authorizeSecurityGroupIngress ( Scalr\Service\Aws\Ec2\DataType\IpPermissionList $ipPermissions, string $groupId = null, string $groupName = null ) : boolean
$ipPermissions Scalr\Service\Aws\Ec2\DataType\IpPermissionList Ip permission list object
$groupId string optional The ID of the EC2 or VPC security group to modify. The group must belong to your account.
$groupName string optional The name of the EC2 security group to modify. It can be used instead of group ID for EC2 security groups.
return boolean Returns true on success
    public function authorizeSecurityGroupIngress(IpPermissionList $ipPermissions, $groupId = null, $groupName = null)
    {
        $result = false;
        $options = $ipPermissions->getQueryArrayBare('IpPermissions');
        if ($groupName === null && $groupId === null || $groupName !== null && $groupId !== null) {
            throw new \InvalidArgumentException(sprintf('Either groupName or groupId is required for the %s. ' . 'Also you cannot specify both in the same call.', __METHOD__));
        }
        if ($groupId !== null) {
            $options['GroupId'] = (string) $groupId;
        } else {
            if ($groupName !== null) {
                $options['GroupName'] = (string) $groupName;
            }
        }
        $response = $this->client->call(ucfirst(__FUNCTION__), $options);
        if ($response->getError() === false) {
            $sxml = simplexml_load_string($response->getRawContent());
            if ((string) $sxml->return != 'true') {
                throw new Ec2Exception(sprintf('Amazon Ec2 could not add ingress rules to a security group "%s". It returned "%s"', $options['GroupId'] ?: $options['GroupName'], $sxml->return));
            }
            $result = true;
        }
        return $result;
    }
Ec2Api