Back to Aws Doc Sdk Examples

Auto Scaling code examples for the SDK for PHP

php/example_code/auto-scaling/README.md

latest4.7 KB
Original Source

Auto Scaling code examples for the SDK for PHP

Overview

Shows how to use the AWS SDK for PHP to work with Amazon EC2 Auto Scaling.

<!--custom.overview.start--> <!--custom.overview.end-->

Auto Scaling automatically scales EC2 instances, either with scaling policies or with scheduled scaling.

⚠ Important

  • Running this code might result in charges to your AWS account. For more details, see AWS Pricing and Free Tier.
  • Running the tests might result in charges to your AWS account.
  • We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
  • This code is not tested in every AWS Region. For more information, see AWS Regional Services.
<!--custom.important.start--> <!--custom.important.end-->

Code examples

Prerequisites

For prerequisites, see the README in the php folder.

<!--custom.prerequisites.start--> <!--custom.prerequisites.end-->

Get started

Basics

Code examples that show you how to perform the essential operations within a service.

Single actions

Code excerpts that show you how to call individual service functions.

<!--custom.examples.start--> <!--custom.examples.end-->

Run the examples

Instructions

<!--custom.instructions.start-->

From the aws-doc-sdk-examples/php/auto-scaling/ directory:

Install dependencies by using Composer:

composer install

After your Composer dependencies are installed, you can run the example with the following command:

php Runner.php
<!--custom.instructions.end-->

Hello Auto Scaling

This example shows you how to get started using Auto Scaling.

Learn the basics

This example shows you how to do the following:

  • Create an Amazon EC2 Auto Scaling group with a launch template and Availability Zones, and get information about running instances.
  • Enable Amazon CloudWatch metrics collection.
  • Update the group's desired capacity and wait for an instance to start.
  • Terminate an instance in the group.
  • List scaling activities that occur in response to user requests and capacity changes.
  • Get statistics for CloudWatch metrics, then clean up resources.
<!--custom.basic_prereqs.auto-scaling_Scenario_GroupsAndInstances.start--> <!--custom.basic_prereqs.auto-scaling_Scenario_GroupsAndInstances.end--> <!--custom.basics.auto-scaling_Scenario_GroupsAndInstances.start--> <!--custom.basics.auto-scaling_Scenario_GroupsAndInstances.end-->

Tests

⚠ Running tests might result in charges to your AWS account.

To find instructions for running these tests, see the README in the php folder.

<!--custom.tests.start-->

Install dependencies by using Composer:

composer install

Run the tests with the following command:

../vendor/bin/phpunit AutoScalingBasicsTests.php
<!--custom.tests.end-->

Additional resources

<!--custom.resources.start--> <!--custom.resources.end-->

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0