3

I would like to know is there a simple way to reduce the AWS PHP SDK to use only S3 ? I tried to delete certain directory but there are so many it will take an incredible time, and I have many errors depending on the files I delete (21,6Mo - 2 368 elements) ?! Is it possible to know the architecture of the basic files necessary to use only S3 with the SDK PHP please?

I found old posts on this subject but the file structure has changed and they are no longer current.

The complete SDK is very heavy with a lot of files that I don't need to keep my sources with an optimization in reasonable size.

Thanks for your help

Nicolas
  • 33
  • 3

4 Answers4

2

The SDK itself now has a (beta) feature to help you out. Check out https://github.com/aws/aws-sdk-php/tree/master/src/Script/Composer

Basically you require the framework with composer, then specify a script to remove unused services, then define the services you want to keep based on their root namespace.

The example from the page is given below

{
    "require": {
        "aws/aws-sdk-php": "<version here>"
    },
    "scripts": {
        "pre-autoload-dump": "Aws\\Script\\Composer\\Composer::removeUnusedServices"
    },
    "extra": {
        "aws/aws-sdk-php": [
            "Ec2",
            "CloudWatch"
        ]
    }
}
Mark
  • 330
  • 2
  • 9
1

Unfortunately to use the SDK you will need to use the entire directory (and all of its individual dependencies).

Whilst you could prune individual directories and files you would then be responsible for maintaining this, including new features which may require additional classes

Best practice for pulling in the SDK is to use the composer dependency manager.

If you were looking for a lighter version you would need to look for someone else's implementation or look at implementing your own library to interact with the AWS S3 API endpoints.

Chris Williams
  • 32,215
  • 4
  • 30
  • 68
  • 1
    Thank you for your quick reply. Do you think the impact is significant in terms of loading and using the PHP SDK for a high demand for service? I think in particular in terms of file upload to the S3 if many users send multiple files at the same time. – Nicolas Jun 15 '20 at 09:28
  • I would be confident that your application should be fine, however it all comes down to resources and other software for throughput. You also have the ability to batch up by doing multiple object uploads which can reduce the number of API calls you're making – Chris Williams Jun 15 '20 at 09:33
  • 1
    I will seek and test in this direction, thank you for your help. – Nicolas Jun 15 '20 at 09:45
  • No problem, glad to help :) – Chris Williams Jun 15 '20 at 09:50
1

I would highly recommend https://async-aws.com/. You can install each component separately. Maybe it not cover every AWS feature, but S3 is supported for years.

Styx
  • 1,303
  • 1
  • 19
  • 30
  • The default `aws-sdk-php` was taking ages to install and you have to put `"process-timeout":0` in composer config so it won't timeout. Meanwhile `async-aws` installs like a normal sane compsoser package -- it should be the default these days. – IMB Jun 21 '23 at 08:50
0

Nicolas and Chris,

A Wordpress plugin-related blog entry led me to this S3 SDK Git project by developer Ian Jones that may help resolve this for you, or others in future. The blog article explains the background and reasoning behind the code.

It's a script he wrote for downloading the AWS PHP SDK v3, stripping it down to the relevant S3 functionality, and then applying a custom namespace to avoid potential clashes.

Hoping to try this myself soon, but also for use with the Rekognition API (but I'm at beginner level!).

https://gist.github.com/ianmjones/55eb1ace80517f951e392b95a65f277b

Regards, Graham

Invisionary
  • 61
  • 1
  • 5