Missing required client configuration options:version when attempting to upload a file to S3

Asked 2 years ago, Updated 2 years ago, 103 views

http://j-caw.co.jp/blog/?p=1100

I am thinking of building a file upload to S3 by referring to the above URL, but I get the following error.
What is the cause of this?

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Missing required client configuration options: version: (string) A "version" configuration value is required. Specifying a version constraint ensures that your code will not be affected by a breaking change made to the service. For example, when using Amazon S3, you can lock your API version to "2006-03-01". Your build of the SDK has the following version(s) of "s3": * "2006-03-01" You may provide "latest" to the "version" configuration value to utilize the most recent available API version that your client's API provider can find. Note: Using 'latest' in a production application is not recommended. A list of available API versions can be found on each client's API documentation page: http://docs.aws.amazon.com/aws-sdk-php/v3/api/index.html.If you are enable to load a specific API version, then you may need to update your copy of the SDK.' in phar://home/for815/www/admin/s3/aws.phar/Aws/ClientResolver.php:328 Stay phar://home/for815/www/admin/s3/aws.phar/Aws/ClientResolver.php on line 328

php aws amazon-s3

2022-09-29 21:20

1 Answers

Fatal error: Uncaught exception 'FooException' with message 'yyyy' in...

An error in the format above indicates that an exception occurred, but was not handled by the try..catch block.The important part is with message 'yyyy', which often describes why the exception was made.

In this case Missing required client configuration options: version: (string) A "version" configuration value is required. and the option version is not specified.

In the AWS SDK for PHP, v3 was released in May this year, and now it is available to download from the official website, but it seems that the version and region options are required.The reference site was probably written around AWS SDK v2.

When instantiating a client for any service, you must specify the 'region' and 'version' options. In version 2 of the SDK, 'version' was completely optional, and 'region' was sometimes optional. In version 3, both are always required. Being explicit about both of these options allows you to lock into the API version and region you are coding against. When new API versions are created or new regions become available, you will be isolated from potentially breaking changes until you are ready to explicitly update your configuration.
--- Quoted from http://docs.aws.amazon.com/aws-sdk-php/v3/guide/guide/migration.html

API may change specifications in the future, but if you specify the version and region, you can avoid unintentionally changing behavior and becoming a problem.

Therefore, I think the choice will be one of the following:

  • Get AWS SDK v2
    I haven't confirmed how long it will be supported, but it seems that it can be downloaded from the following URL.Or specify the version in Composer.
    https://github.com/aws/aws-sdk-php/releases/tag/2.8.24
  • Migrating to AWS SDK v3
    However, some changes are needed, such as deprecating the factory and moving the key secret option into credentials.Both are in English, but it may be faster to read the Migration Guide, or the Getting Started in v3.

See also


2022-09-29 21:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.