forked from amazonwebservices/aws-sdk-for-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudformation.class.php
317 lines (279 loc) · 17.6 KB
/
cloudformation.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
/*
* Copyright 2010-2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
/**
*
* This is the AWS CloudFormation API Reference.
*
* This guide is for programmers who need detailed information about the CloudFormation APIs. You use AWS CloudFormation to
* create and manage AWS infrastructure deployments predictably and repeatedly. CloudFormation helps you leverage AWS
* products such as Amazon EC2, EBS, Amazon SNS, ELB, and Auto Scaling to build highly-reliable, highly scalable, cost
* effective applications without worrying about creating and configuring the underlying the AWS infrastructure.
*
* Through the use of a template file you write, and a few AWS CloudFormation commands or API actions, AWS CloudFormation
* enables you to manage a collection of resources together as a single unit called a stack. AWS CloudFormation creates and
* deletes all member resources of the stack together and manages all dependencies between the resources for you.
*
* For more information about this product, go to the <a
* href="http://aws.amazon.com/documentation/cloudformation">CloudFormation Product Page</a>.
*
* Amazon CloudFormation makes use of other AWS products. If you need additional technical information about a specific AWS
* product, you can find the product's technical documentation at http://aws.amazon.com/documentation/.
*
* @version Fri Mar 25 13:12:48 PDT 2011
* @license See the included NOTICE.md file for complete information.
* @copyright See the included NOTICE.md file for complete information.
* @link http://aws.amazon.com/cloudformation/Amazon CloudFormation
* @link http://aws.amazon.com/documentation/cloudformation/Amazon CloudFormation documentation
*/
class AmazonCloudFormation extends CFRuntime
{
/*%******************************************************************************************%*/
// CLASS CONSTANTS
/**
* Specify the default queue URL.
*/
const DEFAULT_URL = 'cloudformation.us-east-1.amazonaws.com';
/**
* Specify the queue URL for the US-East (Northern Virginia) Region.
*/
const REGION_US_E1 = self::DEFAULT_URL;
/**
* Specify the queue URL for the US-West (Northern California) Region.
*/
const REGION_US_W1 = 'cloudformation.us-west-1.amazonaws.com';
/**
* Specify the queue URL for the EU (Ireland) Region.
*/
const REGION_EU_W1 = 'cloudformation.eu-west-1.amazonaws.com';
/**
* Specify the queue URL for the Asia Pacific (Singapore) Region.
*/
const REGION_APAC_SE1 = 'cloudformation.ap-southeast-1.amazonaws.com';
/**
* Specify the queue URL for the Asia Pacific (Japan) Region.
*/
const REGION_APAC_NE1 = 'cloudformation.ap-northeast-1.amazonaws.com';
/*%******************************************************************************************%*/
// SETTERS
/**
* This allows you to explicitly sets the region for the service to use.
*
* @param string $region (Required) The region to explicitly set. Available options are <REGION_US_E1>, <REGION_US_W1>, <REGION_EU_W1>, or <REGION_APAC_SE1>.
* @return $this A reference to the current instance.
*/
public function set_region($region)
{
$this->set_hostname($region);
return $this;
}
/*%******************************************************************************************%*/
// CONSTRUCTOR
/**
* Constructs a new instance of <AmazonCloudFormation>.
*
* @param string $key (Optional) Your Amazon API Key. If blank, it will look for the <code>AWS_KEY</code> constant.
* @param string $secret_key (Optional) Your Amazon API Secret Key. If blank, it will look for the <code>AWS_SECRET_KEY</code> constant.
* @return boolean false if no valid values are set, otherwise true.
*/
public function __construct($key = null, $secret_key = null)
{
$this->api_version = '2010-05-15';
$this->hostname = self::DEFAULT_URL;
if (!$key && !defined('AWS_KEY'))
{
throw new CloudFormation_Exception('No account key was passed into the constructor, nor was it set in the AWS_KEY constant.');
}
if (!$secret_key && !defined('AWS_SECRET_KEY'))
{
throw new CloudFormation_Exception('No account secret was passed into the constructor, nor was it set in the AWS_SECRET_KEY constant.');
}
return parent::__construct($key, $secret_key);
}
/*%******************************************************************************************%*/
// SERVICE METHODS
/**
*
* Creates a stack as specified in the template. Once the call completes successfully, the stack creation starts. You can
* check the status of the stack via the DescribeStacks API.
*
* AWS CloudFormation allows you to create and delete related AWS resources together as a unit called a stack. You define
* the characteristics of a stack using a template, which is a JSON-compliant text file. For more information, go to the <a
* href="http://docs.amazonwebservices.com/AWSCloudFormation/latest/CFNGuide">AWS CloudFormation User Guide</a>.
*
* Currently, the quota for stacks is 20 per region.
*
* @param string $stack_name (Required) The name associated with the Stack. The name must be unique within your AWS account. Must contain only alphanumeric characters (case sensitive) and start with an alpha character. Maximum length of the name is 255 characters.
* @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
* <li><code>TemplateBody</code> - <code>string</code> - Optional - Structure containing the template body. (For more information, go to the AWS CloudFormation User Guide.) You must pass <code>TemplateBody</code> or <code>TemplateURL</code>. If both are passed, only <code>TemplateBody</code> is used. </li>
* <li><code>TemplateURL</code> - <code>string</code> - Optional - Location of file containing the template body. (For more information, go to the AWS CloudFormation User Guide.) You must pass <code>TemplateURL</code> or <code>TemplateBody</code>. If both are passed, only <code>TemplateBody</code> is used. </li>
* <li><code>Parameters</code> - <code>array</code> - Optional - A list of <code>Parameter</code> structures. <ul>
* <li><code>x</code> - <code>array</code> - This represents a simple array index. <ul>
* <li><code>ParameterKey</code> - <code>string</code> - Optional - The key associated with the parameter. </li>
* <li><code>ParameterValue</code> - <code>string</code> - Optional - The value associated with the parameter. </li>
* </ul></li>
* </ul></li>
* <li><code>DisableRollback</code> - <code>boolean</code> - Optional - Boolean to enable or disable rollback on stack creation failures. Default: <code>false</code> </li>
* <li><code>TimeoutInMinutes</code> - <code>integer</code> - Optional - If the time limit is exceeded, the stack is marked CREATE_FAILED; if <code>RollbackOnFailure</code> is set, the stack will be rolled back. </li>
* <li><code>NotificationARNs</code> - <code>string|array</code> - Optional - The Simple Notification Service (SNS) topic ARNs to publish stack related events. You can find your SNS topic ARNs using the SNS console or your Command Line Interface (CLI). Pass a string for a single value, or an indexed array for multiple values. </li>
* <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <php:curl_setopt()>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
* <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
* @return CFResponse A <CFResponse> object containing a parsed HTTP response.
*/
public function create_stack($stack_name, $opt = null)
{
if (!$opt) $opt = array();
$opt['StackName'] = $stack_name;
// Optional parameter
if (isset($opt['Parameters']))
{
$opt = array_merge($opt, CFComplexType::map(array(
'Parameters' => $opt['Parameters']
), 'member'));
unset($opt['Parameters']);
}
// Optional parameter
if (isset($opt['NotificationARNs']))
{
$opt = array_merge($opt, CFComplexType::map(array(
'NotificationARNs' => (is_array($opt['NotificationARNs']) ? $opt['NotificationARNs'] : array($opt['NotificationARNs']))
), 'member'));
unset($opt['NotificationARNs']);
}
return $this->authenticate('CreateStack', $opt, $this->hostname);
}
/**
*
* Validates a specified template.
*
* @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
* <li><code>TemplateBody</code> - <code>string</code> - Optional - Structure containing the template body. (For more information, go to the AWS CloudFormation User Guide.) </li>
* <li><code>TemplateURL</code> - <code>string</code> - Optional - Location of file containing the template body. (For more information, go to the AWS CloudFormation User Guide.) </li>
* <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <php:curl_setopt()>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
* <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
* @return CFResponse A <CFResponse> object containing a parsed HTTP response.
*/
public function validate_template($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('ValidateTemplate', $opt, $this->hostname);
}
/**
*
* Returns the description for the specified stack; if no stack name was specified, then it returns the description for
* all the stacks created.
*
* If a specified stack does not exist or has been successfully deleted, a <code>ValidationError</code> is returned.
*
* @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
* <li><code>StackName</code> - <code>string</code> - Optional - The name or the unique identifier associated with the stack. Default: <code>null</code> </li>
* <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <php:curl_setopt()>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
* <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
* @return CFResponse A <CFResponse> object containing a parsed HTTP response.
*/
public function describe_stacks($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('DescribeStacks', $opt, $this->hostname);
}
/**
*
* Returns all the stack related events for the AWS account. If <code>StackName</code> is specified, returns events
* related to all the stacks with the given name. If <code>StackName</code> is not specified, returns all the events for
* the account. For more information about a stack's event history, go to the <a
* href="http://docs.amazonwebservices.com/AWSCloudFormation/latest/CFNGuide">AWS CloudFormation User Guide</a>.
*
* Events are returned, even if the stack has been successfully deleted. If the stack never existed, a
* <code>ValidationError</code> is returned.
*
* @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
* <li><code>StackName</code> - <code>string</code> - Optional - The name or the unique identifier associated with the stack. Default: <code>null</code> </li>
* <li><code>NextToken</code> - <code>string</code> - Optional - String that identifies the start of the next list of events, if there is one. Default: <code>null</code> </li>
* <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <php:curl_setopt()>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
* <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
* @return CFResponse A <CFResponse> object containing a parsed HTTP response.
*/
public function describe_stack_events($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('DescribeStackEvents', $opt, $this->hostname);
}
/**
*
* Returns the template body for a specified stack name.
*
* If the stack does not exist or the stack has been successfully deleted, a <code>ValidationError</code> is returned.
*
* @param string $stack_name (Required) The name or the unique identifier associated with the stack.
* @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
* <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <php:curl_setopt()>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
* <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
* @return CFResponse A <CFResponse> object containing a parsed HTTP response.
*/
public function get_template($stack_name, $opt = null)
{
if (!$opt) $opt = array();
$opt['StackName'] = $stack_name;
return $this->authenticate('GetTemplate', $opt, $this->hostname);
}
/**
*
* Deletes a specified stack. Once the call completes successfully, stack deletion starts. Deleted stacks do not show up
* in the DescribeStacks API if the deletion has been completed successfully.
*
* @param string $stack_name (Required) The name or the unique identifier associated with the stack.
* @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
* <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <php:curl_setopt()>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
* <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
* @return CFResponse A <CFResponse> object containing a parsed HTTP response.
*/
public function delete_stack($stack_name, $opt = null)
{
if (!$opt) $opt = array();
$opt['StackName'] = $stack_name;
return $this->authenticate('DeleteStack', $opt, $this->hostname);
}
/**
*
* Returns AWS resource descriptions. If <code>StackName</code> is specified, all the associated resources that are part
* of the stack are returned. If <code>PhysicalResourceId</code> is specified, all the associated resources of the stack
* the resource belongs to are returned.
*
* You can use <code>LogicalResourceId</code> to filter the returned result. For more information about resources, the
* <code>LogicalResourceId</code> and <code>PhysicalResourceId</code>, go to the <a
* href="http://docs.amazonwebservices.com/AWSCloudFormation/latest/CFNGuide">AWS CloudFormation User Guide</a>.
*
* If the stack does not exist or the stack has been successfully deleted, a <code>ValidationError</code> is returned.
*
* @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
* <li><code>StackName</code> - <code>string</code> - Optional - The name or the unique identifier associated with the stack. Default: <code>null</code> </li>
* <li><code>LogicalResourceId</code> - <code>string</code> - Optional - The logical name of the resource specified in the template. Default: <code>null</code> </li>
* <li><code>PhysicalResourceId</code> - <code>string</code> - Optional - The name or unique identifier that corresponds to a physical instance ID of a resource supported by AWS CloudFormation. For example, for an Amazon Elastic Compute Cloud (EC2) instance, <code>PhysicalResourceId</code> corresponds to the <code>InstanceId</code>. You can pass the EC2 <code>InstanceId</code> to <code>DescribeStackResources</code> to find what stack the instance belongs to and what other resources are part of the stack. Default: <code>null</code> </li>
* <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <php:curl_setopt()>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
* <li><code>returnCurlHandle</code> - <code>boolean</code> - 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.</li></ul>
* @return CFResponse A <CFResponse> object containing a parsed HTTP response.
*/
public function describe_stack_resources($opt = null)
{
if (!$opt) $opt = array();
return $this->authenticate('DescribeStackResources', $opt, $this->hostname);
}
}
/*%******************************************************************************************%*/
// EXCEPTIONS
/**
* Default CloudFormation Exception.
*/
class CloudFormation_Exception extends Exception {}