### Install AWS SDK for PHP Source: https://github.com/aws/aws-sdk-php/blob/master/README.md Use Composer to install the AWS SDK for PHP as a project dependency. Ensure Composer is installed globally. ```bash composer require aws/aws-sdk-php ``` -------------------------------- ### Create an Amazon S3 Client Source: https://github.com/aws/aws-sdk-php/blob/master/README.md Instantiate an Amazon S3 client using the AWS SDK for PHP. Requires the Composer autoloader and specifies the client version and region. ```php 'latest', 'region' => 'us-west-2' ]); ``` -------------------------------- ### Instantiate DynamoDB Client with Specific API Version Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Use the 'version' option when instantiating the DynamoDB client to specify an older API version, preventing breaking changes from newer APIs. ```php use Aws\DynamoDb\DynamoDbClient; $client = DynamoDbClient::factory(array( 'key' => '', 'secret' => '', 'region' => '', 'version' => '2011-12-05' )); ``` -------------------------------- ### Create an Amazon S3 Encryption Client V3 Source: https://github.com/aws/aws-sdk-php/blob/master/src/S3/Crypto/README.md Instantiates an Amazon S3 client and then an S3 Encryption Client V3. Requires Composer autoloader and PHP >= 8.1 with the openssl extension. ```php 'latest', 'region' => 'us-west-2' ]); // Instantiate an Amazon S3 Encryption Client V3. $client = new S3EncryptionClientV3($s3Client); ``` -------------------------------- ### Configure Lambda Client for Older API Version Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Use this configuration to maintain compatibility with the older 2014-11-11 API version for AWS Lambda if needed. ```php use Aws\Lambda\LambdaClient; $client = LambdaClient::factory(array( 'version' => '2014-11-11', // ... )); ``` -------------------------------- ### 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.ini file to enable the AWS CRT extension. Ensure the path to `awscrt.so` is correct for your system. ```ini extension=path/to/aws-crt-php/modules/awscrt.so ``` -------------------------------- ### Changelog Document Structure Source: https://github.com/aws/aws-sdk-php/blob/master/CONTRIBUTING.md A changelog document is a JSON blob used to describe updates. It requires a type (feature, enhancement, bugfix), a category, and a description. ```json [ { "type": "feature|enhancement|bugfix", "category": "Target of Update", "description": "English language simple description of your update." } ] ``` -------------------------------- ### Configure CloudSearch Client for Older API Version Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Configure the CloudSearch client to use the older 2011-02-01 API version if you need to maintain compatibility with previous versions. ```php use Aws\CloudSearch\CloudSearchClient; $client = CloudSearchClient::factory(array( 'key' => '', 'secret' => '', 'region' => '', 'version' => '2011-02-01', )); ``` -------------------------------- ### Configure Composer to Remove Unused Services Source: https://github.com/aws/aws-sdk-php/blob/master/src/Script/Composer/README.md Specify services to keep in `composer.json` and use the `Aws\Script\Composer::removeUnusedServices` script. Ensure exact client namespace matches when listing services. ```json { "require": { "aws/aws-sdk-php": "" }, "scripts": { "pre-autoload-dump": "Aws\Script\Composer\Composer::removeUnusedServices" }, "extra": { "aws/aws-sdk-php": [ "Ec2", "CloudWatch" ] } } ``` -------------------------------- ### Update AWS CloudTrail CreateTrail API Call Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Demonstrates the change from passing a 'trail' object to individual parameters for the CreateTrail API. Update your code to use the new parameter structure to avoid breaking changes. ```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', )); ``` -------------------------------- ### Upload a File to Amazon S3 Source: https://github.com/aws/aws-sdk-php/blob/master/README.md Upload a file to an Amazon S3 bucket using the `putObject` method. The file is made publicly accessible. Handles potential S3 exceptions. ```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"; } ``` -------------------------------- ### Configure DynamoDB Client Version in AWS SDK for PHP Config File Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md Modify the AWS SDK for PHP configuration file to specify an older API version for the DynamoDB service, ensuring compatibility. ```json { "includes": ["_aws"], "services": { "default_settings": { "params": { "key": "", "secret": "", "region": "" } }, "dynamodb": { "extends": "dynamodb", "params": { "version": "2011-12-05" } } } } ``` -------------------------------- ### Update EC2 RequestSpotInstances Monitoring Parameter Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md This snippet demonstrates the change from the old 'MonitoringEnabled' parameter to the new nested 'Monitoring.Enabled' structure for the RequestSpotInstances operation in the AWS SDK for PHP. Update your code if you are using this specific parameter. ```php // The OLD way $result = $ec2->requestSpotInstances(array( // ... 'LaunchSpecification' => array( // ... 'MonitoringEnabled' => true, // ... ), // ... )); ``` ```php // The NEW way $result = $ec2->requestSpotInstances(array( // ... 'LaunchSpecification' => array( // ... 'Monitoring' => array( 'Enabled' => true, ), // ... ), // ... )); ``` -------------------------------- ### Upload a file to Amazon S3 using client-side encryption Source: https://github.com/aws/aws-sdk-php/blob/master/src/S3/Crypto/README.md Uploads a file to S3 with client-side encryption using a KMS key. Ensure the KMS key ID, bucket name, and file path are correctly configured. The CommitmentPolicy and KmsEncryptionContext can be customized. ```php $kmsKeyId = 'kms-key-id'; $materialsProvider = new KmsMaterialsProviderV3( new KmsClient([ 'profile' => 'default', 'region' => 'us-east-1', 'version' => 'latest', ]), $kmsKeyId ); $bucket = 'the-bucket-name'; $key = 'the-file-name'; $cipherOptions = [ 'Cipher' => 'gcm', 'KeySize' => 256, // Additional configuration options ]; $result = $client->putObject([ '@MaterialsProvider' => $materialsProvider, '@CipherOptions' => $cipherOptions, '@CommitmentPolicy' => 'REQUIRE_ENCRYPT_REQUIRE_DECRYPT', '@KmsEncryptionContext' => ['context-key' => 'context-value'], 'Bucket' => $bucket, 'Key' => $key, 'Body' => fopen('file-to-encrypt.txt', 'r'), ]); ``` -------------------------------- ### Invoke S3 Waiter with Associative Array Input Source: https://github.com/aws/aws-sdk-php/blob/master/UPGRADING.md When using waiters, provide an associative array for the underlying operation's parameters, including waiter-specific options like 'waiter.max_attempts'. ```php $s3Client->waitUntilObjectExists(array( 'Bucket' => 'foo', 'Key' => 'bar', 'waiter.max_attempts' => 3 )); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.