0

I am attempting to send a message to SQS and I have followed instructions laid here

https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/sqs-examples-send-receive-messages.html

However, when I follow these I do not get anything, not even an error message. The code is as follows:

use Aws\Exception\AwsException;
use Aws\Credentials\Credentials;
use Aws\Sqs\SqsClient; 
$credentials = new Credentials('IAM account key', 'IAM secret key')
    $sqsClient = new SqsClient([
        'version' => '2012-11-05',
    'credentials' => $credentials,
    'region' => 'eu-north-1',
  ]);

//Debug values, these would later be filled from database
$params = [
    'DelaySeconds' => 10,
    'MessageAttributes' => [
        "SocialSecurityCode" => [
            'DataType' => "String",
            'StringValue' => "111111-1"
        ],
        "Name" => [
            'DataType' => "String",
            'StringValue' => "Teemu Testaaja"
        ],
        "PeriodStart" => [
            'DataType' => "String",
            'StringValue' => "1-1-2019"
        ],
        "PeriodEnd" => [
            'DataType' => "String",
            'StringValue' => "31-1-2019"
        ],
        "EventDate" => [
            'DataType' => "String",
            'StringValue' => "12-1-2019"
        ],
        "Code" => [
            'DataType' => "Number",
            'StringValue' => "12"
        ],
        "Amount" => [
            'DataType' => "Number",
            'StringValue' => "7.5"
        ]
    ],
    'MessageBody' => "Test message",
    'QueueUrl' => 'sqs-url from the console'
];

try {
    print("Sending message");
    $result = $sqsClient->sendMessage($params);
    print("Message send");
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    print("ERROR!");
    var_dump($e->getMessage());
}

Yet, only thing I get out is "Sending message". What am I doing wrong here? I have an IAM account set up with ability to send and read messages from the queu.

I tried to look at the queu to see if messages did pass and there was something else, but there are no items in the queu and there is currently nothing reading it.

Code is hosted on Amazon AWS server.

UPDATE

As of now, messages are correctly passed to the queu, but code does not proceed from sendMessages part forward.

Mandemon
  • 372
  • 3
  • 22
  • Have you made sure you can [see any and all errors](https://stackoverflow.com/questions/845021/how-can-i-get-useful-error-messages-in-php)? – Phil May 25 '20 at 06:22
  • If you check the CloudWatch metrics for this SQS queue do you see anything at all? – Chris Williams May 25 '20 at 06:26
  • Where are you executing this? On your local workstation, or on some ec2 instance in a vpc? – Marcin May 25 '20 at 06:26
  • @Phil As far as I know. I do not have full access to the system. – Mandemon May 25 '20 at 06:31
  • @mokugo-devops what i should be looking for in CloudWatch? I can see the SQS service and it shows now errors. – Mandemon May 25 '20 at 06:31
  • @Marcin At the AWS server. – Mandemon May 25 '20 at 06:31
  • Seems to me its timing out if it hangs on `$sqsClient->sendMessage($params);`. Can you confirm that you have internet access or can manually send messages to the sqs using AWS CLI? – Marcin May 25 '20 at 06:32
  • 1
    @Marcin Confirmed that I can send message using AWS CLI. – Mandemon May 25 '20 at 06:39
  • 1
    Ok, so queue is reachable. Using aws cli, have you used the same `$credentials` as in the code? As a side note, better to use instance roles for access to sqs, rather then hardcoding keys in the code. – Marcin May 25 '20 at 06:41
  • Hi @Mandemon just connect to CloudWatch and see if there are any metrics for your SQS queue at all – Chris Williams May 25 '20 at 06:42
  • Hi, did you dump `$params` to check the content? Is content looks ok (QueueUrl ...)? – qdequippe May 25 '20 at 06:46
  • @Marcin agreed on using instance roles, but these are for debugging purposes until everything works. As far as I can see, credentials are the same – Mandemon May 25 '20 at 07:03
  • So it seems that there is something wrong with the php code. Just by looking at it I don't know at present what can be wrong. Maybe have to enable these extra errors, which @Phil mentioned, and look for some error messages. – Marcin May 25 '20 at 07:06
  • @qdequippe Yes, it matches what is seen – Mandemon May 25 '20 at 07:06
  • @Marcin I request the changed made to allow full error reporting. Still nothing. – Mandemon May 25 '20 at 07:21
  • @Phil I request the changed made to allow full error reporting. Still nothing – Mandemon May 25 '20 at 07:21
  • Update: Message are now passing through(SQS shows new messages appearing), but code still stops on the sendMessage. I updated code to form seen in original post now to confirm that this. – Mandemon May 25 '20 at 07:24
  • So what was wrong that now it sends messages? – Marcin May 25 '20 at 07:30
  • @Marcin Bugger if I know, it now sends the messages correctly. I am tempted to say Wizard Did It to be honest. This started after .htaccess was changed to allow larger error reporting as per Phils link. However, the code still seems to hang up on sendMessage part, not proceeding from there. – Mandemon May 25 '20 at 07:41
  • At least there is some progress. – Marcin May 25 '20 at 07:42

0 Answers0