douyeyan0650 2017-09-08 16:21
浏览 64
已采纳

无法从我的EC2实例中提取SQS消息

When I deploy my application to a EC2 instance, it fails to fetch messages from my SQS queue. And instead throws an exception with the status code 403 Forbidden, access to the resource {sqs queue} is denied. However, when I run the same code from my local environment my application can fetch messages from the SQS queue.

My application uses the symfony framework and passes pre-configured AWS credentials, for a user who has access to this queue, from the parameters.yml into \Aws\Sqs\SqsClient().

If on the EC2 instance I run aws configure and configure the aws cli with the same credentials the application can pull messages from the SQS queue. I am concerned here because it is like the aws sdk is overriding the credentials I pass it.

As a example the following code even with hard coded parameters which I have checked are valid credentials, returns a 403 when ran on a EC2 instances.

 $sqs = new \Aws\Sqs\SqsClient([
        [
            'key' => '{my key}',
            'secret' => '{my secret}'
        ],
        'region' => 'us-east-1',
        'version' => 'latest'
    ]);

    $response = $sqs->receiveMessage([
        'QueueUrl' => 'https://sqs.us-east-1.amazonaws.com/{my account}/{my queue}'
    ]);

Does anyone have any suggestions about what may be happening here?

  • 写回答

2条回答 默认 最新

  • dongyi1524 2017-09-08 17:14
    关注

    Try with credentials key in config.

    $sqs = new \Aws\Sqs\SqsClient([
        'credentials' => [
                'key'    => '{my key}',
                'secret' => '{my secret}',
            ],
            'region' => 'us-east-1',
            'version' => 'latest'
        ]);
    
        $response = $sqs->receiveMessage([
            'QueueUrl' => 'https://sqs.us-east-1.amazonaws.com/{my accoun}/{my queue}'
        ]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?