create_security_group ( $group_name, $group_description, $opt )

The CreateSecurityGroup operation creates a new security group.

Every instance is launched in a security group. If no security group is specified during launch, the instances are launched in the default security group. Instances within the same security group have unrestricted network access to each other. Instances will reject network access attempts from other instances in a different security group. As the owner of instances you can grant or revoke specific permissions using the AuthorizeSecurityGroupIngress and RevokeSecurityGroupIngress operations.

Access

public

Parameters

Parameter

Type

Required

Description

$group_name

string

Required

Name of the security group.

$group_description

string

Required

Description of the group. This is informational only.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • VpcId - string - Optional - ID of the VPC.
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Create a new security group.

$ec2 = new AmazonEC2();

$response = $ec2->create_security_group('my-security-group', 'This is a test description.');

var_dump($response->isOK());
Result:
bool(true)

Security groups only support US-ASCII characters.

The example below will fail with an error.

$ec2 = new AmazonEC2();

$response = $ec2->create_security_group('my-security-group', 'åéîøü¡™£¢∞§¶•ªº–≠');

var_dump($response->isOK());
Result:
bool(false)

Create a new security group for a VPC.

$ec2 = new AmazonEC2();

$response = $ec2->create_security_group('my-vpc-security-group', 'This is a test VPC description', array(
	'VpcId' => 'vpc-fd7cd194'
));

var_dump($response->isOK());
Result:
bool(true)

Related Methods

Source

Method defined in services/ec2.class.php | Toggle source view (8 lines) | View on GitHub

public function create_security_group($group_name, $group_description, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['GroupName'] = $group_name;
    $opt['GroupDescription'] = $group_description;
    
    return $this->authenticate('CreateSecurityGroup', $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback