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

createSecurityGroup() public method

Creates a new security group.You can create either an EC2 security group (which works only with EC2), or a VPC security group (which works only with Amazon Virtual Private Cloud). The two types of groups have different capabilities When you create a security group, you give it a friendly name of your choice.You can have an EC2 security group with the same name as a VPC security group (each group has a unique security group ID separate from the name). Two standard groups can't have the same name, and two VPC groups can't have the same name. If you don't specify a security group when you launch an instance, the instance is launched into the default security group. This group (and only this group) includes a default rule that gives the instances in the group unrestricted network access to each other. You have a default EC2 security group for instances you launch with EC2 (i.e., outside a VPC), and a default VPC security group for instances you launch in your VPC.
public createSecurityGroup ( string $groupName, string $groupDescription, string $vpcId = null ) : string
$groupName string The name of the security group.
$groupDescription string A description of the security group. This is information only.
$vpcId string optional The ID of the VPC. (Required for VPC security groups)
return string Returns security group ID on success or throws an exception
    public function createSecurityGroup($groupName, $groupDescription, $vpcId = null)
    {
        $result = null;
        $options = array('GroupName' => (string) $groupName, 'GroupDescription' => (string) $groupDescription);
        if ($vpcId !== null) {
            $options['VpcId'] = (string) $vpcId;
        }
        $response = $this->client->call(ucfirst(__FUNCTION__), $options);
        if ($response->getError() === false) {
            $sxml = simplexml_load_string($response->getRawContent());
            $response = null;
            if ((string) $sxml->return != 'true') {
                throw new Ec2Exception(sprintf('Amazon Ec2 could not create security group %s. It returned "%s"', $groupName, $sxml->return));
            }
            $result = (string) $sxml->groupId;
        }
        return $result;
    }
Ec2Api