Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

How can I set up region? #60

Open
ikovalyov opened this issue Jul 4, 2016 · 3 comments
Open

How can I set up region? #60

ikovalyov opened this issue Jul 4, 2016 · 3 comments

Comments

@ikovalyov
Copy link

ikovalyov commented Jul 4, 2016

$sqs = new Sqs(self::ACCESS_KEY_ID, self::SECRET_KEY, "eu-west-1");
gives
Argument 3 passed to ZendService\Amazon\AbstractAmazon::__construct() must be an instance of Zend\Http\Client, string given, called in .../vendor/zendframework/zendservice-amazon/library/ZendService/Amazon/Sqs/Sqs.php on line 61
error.
Thanks.

@NeilSmith100
Copy link

This class is defective and hasn't been properly maintained.

I found two issues which I needed to extend the class to override myself :

(1) SQS::__construct($accessKey = null, $secretKey = null, $region = null)
This specifies a string in the docblock. If used the string is passed to parent class

Parent class is Amazon\AbstractAmazon and that constructor specifies
__construct($accessKey = null, $secretKey = null, HttpClient $httpClient = null)

(2) The default region is specified by protected property $_sqsEndpoint
This is set to 'queue.amazonaws.com' and it's hard-coded to be used in _signParameters

There is no setter for this endpoint, it is only valid for US East locations.

SQS endpoint varies according to region, as in
http://docs.aws.amazon.com/general/latest/gr/rande.html#sqs_region

Again I had to override this, by extending SQS class so I could set $_sqsEndpoint to 'sqs.eu-west-1.amazonaws.com' needed for my queues (this would also provide correct endpoint for ListQueues and CreateQueue)

This class cannot have been properly tested, and should probably be removed from the Repo until fixed

It is unable to supply defaults without the developer breaking apart the code, and noticing the default SQS hostname is used to create Signature incorrectly for non-USA queue reqions.

@NeilSmith100
Copy link

This is the sample I extended the SQS service with, to make it usable, maybe help to see how it should connect


use ZendService\Amazon\Sqs\Sqs;
use ZendService\Amazon\Sqs\Exception\RuntimeException;

class QueueReaderService extends Sqs
{

    public function __construct(array $aConfig)
    {
        //  NS : Constructor specifies 3rd argument of region (string) but
        //  passes to parent class which requires Zend_HTTP_Client. WRONG.
        parent::__construct($aConfig['accesskey'], $aConfig['secretkey']);

        //  NS : Class has hardcoded $_sqsEndpoint = 'queue.amazonaws.com' : WRONG
        //  this should derive from hostname - which it uses to create Signature
        $this->setSQSRegionEndpoint('sqs.eu-west-1.amazonaws.com');
    }

    /**
     *  @param string
     */
    public function setSQSRegionEndpoint($sRegionEndpoint)
    {
        $this->_sqsEndpoint = $sRegionEndpoint;
    }
}

@Xerkus
Copy link
Member

Xerkus commented Mar 24, 2017

I added quick fix in https://github.com/Xerkus/ZendService_Amazon/tree/feature/sqs-regions
If someone wants to cleanup and test that, i will be happy to merge the PR.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants