CloudFormation client

This page contains examples with the CloudFormation client. See the client introduction for a more detailed description how to use a client. You may also want to consider the authentication documentation to understand the many ways you can authenticate with AWS.

The CloudFormation package could be installed with Composer.

composer require async-aws/cloud-formation

A new client object may be instantiated by:

use AsyncAws\CloudFormation\CloudFormationClient; $cloudFormation = new CloudFormationClient();

The authentication parameters is read from the environment by default. You can also specify a AWS access id and secret:

use AsyncAws\CloudFormation\CloudFormationClient; $cloudFormation = new CloudFormationClient([ 'accessKeyId' => 'my_access_key', 'accessKeySecret' => 'my_access_secret', 'region' => 'eu-central-1', ]);

For all available options, see the configuration reference.

Usage

List stacks

use AsyncAws\CloudFormation\CloudFormationClient; $cloudFormation = new CloudFormationClient(); $result = $cloudFormation->describeStacks(); foreach ($result->getStacks() as $stack) { echo $stack->getStackName().'-'.$stack->getStackStatus().PHP_EOL; }

List stack's events

use AsyncAws\CloudFormation\CloudFormationClient; use AsyncAws\CloudFormation\Input\DescribeStackEventsInput; $cloudFormation = new CloudFormationClient(); $result = $cloudFormation->describeStackEvents(new DescribeStackEventsInput([ 'StackName' => 'cluster-prod', ])); foreach ($result->getStackEvents() as $event) { echo $event->getResourceType().'-'.$event->getResourceStatus().PHP_EOL; }

Detect Stack Drift Status

use AsyncAws\CloudFormation\CloudFormationClient; use AsyncAws\CloudFormation\Input\DescribeStackEventsInput; $cloudFormation = new CloudFormationClient(); $driftStatus = $cloudFormation->describeStackDriftDetectionStatus([ 'StackDriftDetectionId' => 'b78ac9b0-dec1-11e7-a451-503a3example', ]);

The source code to this page is found on GitHub.