### Installing AWS SDK for PHP via Composer (Bash) Source: https://github.com/aws/aws-sdk-php/blob/master/README.md Command to add the AWS SDK for PHP as a project dependency using Composer. This is the recommended installation method and requires Composer to be installed globally on your system. ```bash composer require aws/aws-sdk-php ``` -------------------------------- ### Request Spot Instances with New Monitoring Parameter (PHP) Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Shows the updated structure for specifying the monitoring parameter within the `LaunchSpecification` array for the `requestSpotInstances` operation. The parameter is now nested under a `Monitoring` key with an `Enabled` sub-key. ```php // The NEW way $result = $ec2->requestSpotInstances(array( // ... 'LaunchSpecification' => array( // ... 'Monitoring' => array( 'Enabled' => true, ), // ... ), // ... )); ``` -------------------------------- ### Example Changelog Document Format Source: https://github.com/aws/aws-sdk-php/blob/master/CONTRIBUTING.md This JSON snippet shows the required format for a changelog document placed in the `.changes/nextrelease` folder. It includes fields for the type, category, and a description of the update. ```JSON [ { "type": "feature|enhancement|bugfix", "category": "Target of Update", "description": "English language simple description of your update." } ] ``` -------------------------------- ### Request Spot Instances with Old Monitoring Parameter (PHP) Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Demonstrates the deprecated structure for specifying the monitoring parameter within the `LaunchSpecification` array when calling the `requestSpotInstances` operation. This structure used a direct `MonitoringEnabled` key. ```php // The OLD way $result = $ec2->requestSpotInstances(array( // ... 'LaunchSpecification' => array( // ... 'MonitoringEnabled' => true, // ... ), // ... )); ``` -------------------------------- ### Using S3 Waiter with Associative Array Input (PHP) Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Provides an example of using the `waitUntilObjectExists` waiter on an Amazon S3 client in AWS SDK for PHP 2.1+. Waiters now accept an associative array specifying parameters for the underlying operation (e.g., 'Bucket', 'Key' for HeadObject) and waiter-specific options prefixed with 'waiter.'. ```php $s3Client->waitUntilObjectExists(array( 'Bucket' => 'foo', 'Key' => 'bar', 'waiter.max_attempts' => 3 )); ``` -------------------------------- ### Uploading File to S3 Bucket (PHP) Source: https://github.com/aws/aws-sdk-php/blob/master/README.md Shows how to upload a local file to a specified Amazon S3 bucket using the instantiated S3 client. The example includes basic error handling for S3 exceptions and sets the uploaded object's access control list (ACL). ```php putObject([ 'Bucket' => 'my-bucket', 'Key' => 'my-object', 'Body' => fopen('/path/to/file', 'r'), 'ACL' => 'public-read', ]); } catch (Aws\S3\Exception\S3Exception $e) { echo "There was an error uploading the file.\n"; } ``` -------------------------------- ### Instantiating Amazon CloudSearch Client with Specific API Version (PHP) Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Shows how to instantiate the Amazon CloudSearch client using the older '2011-02-01' API version. This allows users upgrading from SDK v2.5 to v2.6 to continue using the previous CloudSearch API instead of the default 2013-01-01 version, which introduced breaking changes. ```php use Aws\CloudSearch\CloudSearchClient; $client = CloudSearchClient::factory(array( 'key' => '', 'secret' => '', 'region' => '', 'version' => '2011-02-01', )); ``` -------------------------------- ### Instantiating AWS Lambda Client with Specific API Version (PHP) Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Demonstrates how to instantiate the AWS Lambda client using a specific, older API version ('2014-11-11') to maintain compatibility with the preview API during the upgrade from SDK v2.7 to v2.8. This is necessary because the Lambda service API changed significantly. ```php use Aws\Lambda\LambdaClient; $client = LambdaClient::factory(array( 'version' => '2014-11-11', // ... )); ``` -------------------------------- ### Updating AWS CloudTrail createTrail Call - PHP Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Illustrates the required change for the `createTrail` method in the AWS SDK for PHP due to an AWS CloudTrail API update. The method now accepts parameters directly instead of requiring a nested 'trail' object. ```php // The OLD way $cloudTrail->createTrail(array( 'trail' => array( 'Name' => 'TRAIL_NAME', 'S3BucketName' => 'BUCKET_NAME', ) )); // The NEW way $cloudTrail->createTrail(array( 'Name' => 'TRAIL_NAME', 'S3BucketName' => 'BUCKET_NAME', )); ``` -------------------------------- ### Instantiating DynamoDB Client with Specific API Version (PHP) Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Demonstrates how to instantiate the AWS DynamoDB client using a specific API version ('2011-12-05') to maintain compatibility with older codebases when upgrading the SDK. This is achieved by passing the 'version' parameter in the factory configuration array. Requires AWS access key, secret key, and region name. ```php use Aws\DynamoDb\DynamoDbClient; $client = DynamoDbClient::factory(array( 'key' => '', 'secret' => '', 'region' => '', 'version' => '2011-12-05' )); ``` -------------------------------- ### Configuring Composer to Remove Unused AWS Services (JSON) Source: https://github.com/aws/aws-sdk-php/blob/master/src/Script/Composer/README.md This snippet shows how to configure your composer.json file to use the Aws\Script\Composer::removeUnusedServices script. You list the AWS services you want to keep in the "extra" section under "aws/aws-sdk-php". Services not listed (except core ones like S3, Kms, SSO, Sts) will be removed when you run composer install or update. ```JSON { "require": { "aws/aws-sdk-php": "" }, "scripts": { "pre-autoload-dump": "Aws\\Script\\Composer\\Composer::removeUnusedServices" }, "extra": { "aws/aws-sdk-php": [ "Ec2", "CloudWatch" ] } } ``` -------------------------------- ### Configuring DynamoDB Client API Version in JSON File Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Illustrates how to configure the AWS DynamoDB client to use a specific API version ('2011-12-05') within a JSON configuration file used by the AWS SDK for PHP's configuration system. This allows setting the version globally for the 'dynamodb' service. Requires AWS access key, secret key, and region name in the default settings. ```json { "includes": ["_aws"], "services": { "default_settings": { "params": { "key": "", "secret": "", "region": "" } }, "dynamodb": { "extends": "dynamodb", "params": { "version": "2011-12-05" } } } } ``` -------------------------------- ### Instantiating AWS S3 Client (PHP) Source: https://github.com/aws/aws-sdk-php/blob/master/README.md Demonstrates how to create a new instance of the AWS S3 client using the SDK. It requires including the Composer autoloader and configuring the client with the desired AWS version and region. ```php 'latest', 'region' => 'us-west-2' ]); ``` -------------------------------- ### Enable AWS CRT Extension in php.ini Source: https://github.com/aws/aws-sdk-php/blob/master/CRT_INSTRUCTIONS.md Add this line to your PHP configuration file (php.ini) to load the AWS Common Run Time extension. Replace 'path/to/aws-crt-php/modules' with the actual path where the compiled 'awscrt.so' module is located. ```php.ini extension=path/to/aws-crt-php/modules/awscrt.so ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.