Search code examples
phpamazon-web-servicesamazon-s3zend-framework2

How to get aws service with aws-sfk-php-zf2 v 2.0.*?


I was using aws/aws-sdk-php-zf2 1.2.* and had to upgrade to 2.0.* and the AWS SDK is v3 now.

Before I called it using the code:

$this->s3 = $serviceLocator->get('aws')->get('s3');

But now its returning this error:

Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for aws

Couldn't find the difference in the migration documentation.

Any tips?


Solution

  • I found an way that worked for me.

    It's like that now:

    use Aws\S3\S3Client;
    
    $this->s3 = S3Client::factory(array(
                'credentials' => array(
                   'key' => $this->config['aws']['key'],
                   'secret' => $this->config['aws']['secret'],
                ),
                'region' => $this->config['aws']['region'],
                'version' => '2006-03-01'
            ));