AWS SDK for PHP

repository·master·Indexed 27 days ago

https://github.com/aws/aws-sdk-php

A comprehensive interface for interacting with Amazon Web Services (AWS) using PHP, supporting hundreds of services including Amazon S3 and DynamoDB. Key features include Guzzle-based HTTP clients, pagination, waiters, an S3 multipart uploader, S3 stream wrapper, and a DynamoDB session handler. It requires PHP >= 8.1 and provides specialized tools like the S3EncryptionClientV3 for client-side encryption and Composer scripts to remove unused services to reduce deployment size.

Tokens
4.5K
Snippets
13
Records
26
Agent score
88%

What's inside aws-sdk-php

  1. Explore related AWS projects and integrations

    master

    The AWS SDK for PHP has several official and community integrations for popular PHP frameworks and tools:

  2. Key features of the AWS SDK for PHP

    master

    The SDK provides several high-level features for working with AWS:

    • HTTP Clients: Built on Guzzle, supporting persistent connections and asynchronous requests.
    • Pagination & Waiters: Easy result pagination via Paginators and service state monitoring via Waiters.
    • S3 Multipart Uploader: A tool for Amazon S3 and Amazon Glacier that supports pausing and resuming.
    • S3 Stream Wrapper: Allows using native PHP file functions (fopen, etc.) to interact with S3 buckets like a local filesystem.
    • S3 Encryption Client: For creating and interacting with encrypted objects in S3.
    • DynamoDB Session Handler: For scaling sessions using DynamoDB.
    • IAM Instance Profile Credentials: Automatically uses credentials from configured Amazon EC2 instances.
  3. Understand the Amazon S3 Encryption Client for PHP support policy

    master

    The Amazon S3 Encryption Client for PHP receives regular updates including support for new APIs, features, enhancements, bug fixes, security patches, and documentation. Updates also address changes in dependencies, language runtimes, and operating systems.

    It is recommended to stay up-to-date with the latest releases to ensure access to security updates and the latest features. Using unsupported versions is done at the user's discretion.

  4. Revert to the old Amazon CloudFront API in Version 2.4

    master
    Version 2.4 defaults to the 2013-05-12 Amazon CloudFront API, which contains breaking changes. To use the previous 2012-05-05 API, set the version option when instantiating the CloudFront client.
  5. Revert to the old Amazon DynamoDB API in Version 2.3

    master

    Version 2.3 defaults to the 2012-08-10 Amazon DynamoDB API. To use the 2011-12-05 API, specify the version in the DynamoDbClient factory or in your Aws\ Common\\Aws configuration file.

    use Aws\\DynamoDb\\DynamoDbClient;
    
    $client = DynamoDbClient::factory(array(
        'key'     => '<aws access key>',
        'secret'  => '<aws secret key>',
        'region'  => '<region name>',
        'version' => '2011-12-05'
    ));
  6. Get help with the AWS SDK for PHP

    master

    If you need assistance, use the following community resources:

    • StackOverflow: Tag questions with aws-php-sdk.
    • Gitter: Join the AWS SDK for PHP community chat.
    • AWS Support: Open a support ticket via the AWS Console.
    • GitHub Issues: Use for tracking bugs and feature requests (search existing issues first).
    • Amazon Web Services Discussion Forums: For general questions regarding AWS services and limitations.
  7. Use the old Lambda API in Version 2.8

    master

    Version 2.8 is backward-compatible with 2.7, except for the AWS Lambda service which underwent significant API changes. If you need to continue using the 2014-11-11 preview API, specify the version when instantiating the LambdaClient.

    use Aws\
    Lambda\\LambdaClient;
    
    $client = LambdaClient::factory(array(
        'version' => '2014-11-11',
        // ...
    ));
  8. Remove unused AWS services via Composer

    master

    To reduce the size of your deployment by removing unused AWS services, you can configure the SDK to only include specific services.

    1. In your composer.json file, add an extra section for aws/aws-sdk-php containing an array of the service client namespaces you wish to keep.
    2. Add a pre-autoload-dump script to run Aws\Script\Composer\Composer::removeUnusedServices.
    3. Run composer install or composer update to trigger the removal process.

    Important Requirements:

    • You must use the exact client namespace (e.g., Ec2, CloudWatch). An incorrect name will cause an error.
    • S3, Kms, SSO, and Sts are used by the core SDK and are automatically protected from deletion.
    • If you accidentally remove a required service, reinstall the SDK using composer reinstall aws/aws-sdk-php.
    {
        "require": {
            "aws/aws-sdk-php": "<version here>"
        },
        "scripts": {
            "pre-autoload-dump": "Aws\\Script\\Composer\\Composer::removeUnusedServices"
        },
        "extra": {
            "aws/aws-sdk-php": [
                "Ec2",
                "CloudWatch"
            ]
        }
    }
  9. Install and configure the Amazon S3 Encryption Client for PHP V3

    master

    The S3EncryptionClientV3 provides an S3 client that supports client-side encryption.

    Requirements:

    • PHP version: >= 8.1
    • PHP extension: openssl

    To use it, instantiate a standard Aws\S3\S3Client first, then pass that client into the Aws\S3\Crypto\S3EncryptionClientV3 constructor.

    <?php
    // Require the Composer autoloader.
    require 'vendor/autoload.php';
    
    use Aws\S3\S3Client;
    use Aws\S3\Crypto\S3EncryptionClientV3;
    
    // Instantiate an Amazon S3 client.
    $s3 = new S3Client([
        'version' => 'latest',
        'region'  => 'us-west-2'
    ]);
    
    // Instantiate an Amazon S3 Encryption Client V3.
    $client = new S3EncryptionClientV3($s3);
  10. Install the AWS SDK for PHP via Composer

    master

    The recommended way to install the AWS SDK for PHP is using Composer. Run the following command in your project's base directory to add aws/aws-sdk-php as a dependency.

    Minimum Requirements:

    • PHP >= 8.1
    • cURL extension (highly recommended)
    • cURL 7.16.2+ compiled with a TLS backend (e.g., NSS or OpenSSL)
    composer require aws/aws-sdk-php
  11. Update Amazon EC2 RequestSpotInstances parameters for Version 2.5

    master

    In Version 2.5, the LaunchConfiguration.MonitoringEnabled parameter for the RequestSpotInstances operation was changed to a nested structure: LaunchConfiguration.Monitoring.Enabled. If you use this parameter, you must update your request structure.

    // The NEW way
    $result = $ec2->requestSpotInstances(array(
        // ...
        'LaunchSpecification' => array(
            // ...
            'Monitoring' => array(
                'Enabled' => true,
            ),
            // ...
        ),
        // ...
    ));