timkay / aws

Easy command line access to Amazon EC2, S3, SQS, ELB, and SDB
http://timkay.com/aws/
426 stars 126 forks source link

SQS Issues (long polling & delete message on successful exec) #84

Closed nibynool closed 10 years ago

nibynool commented 10 years ago

Hi Tim,

Thanks for the great bit of code. It's making my life significantly easier for a project I am working on.

Despite saying that, I am having a couple of issues with SQS. The first is with long polling (which i notice is a recent commit to master). Maybe I'm missing something, but after adding --wait=20 to the command line long-polling doesn't seem to be working. Have I got the right parameter and format, or am I doing something wrong?

My second issue is a bit more significant. I'm currently using --exec='system("processMessage", "$body"); $?;' and despite the system call returning 0 (there is no message from your script saying otherwise), the message does not get deleted from SQS. Am I mis-reading the docs, are the docs wrong or is there something else?

Thanks in advance for your help.

nibynool commented 10 years ago

Further to my previous message, it appears I have found the cause of the message not getting deleted.

On line 2450 you have my $cmd = qq[$0 dm $argv[0] --handle $handle];. This code does not allow for my use of the --region=us-west-2 parameter and as such I get a AWS.SimpleQueueService.NonExistentQueue response.

Unfortunately I'm a little rusty on perl, so I can't offer a solution to this, but I can't image it would take more than a few minutes for someone with perl knowledge.

timkay commented 10 years ago

I will look into propagating the region information.

As for scripting with "aws" and getting a zero return code, have you read https://github.com/timkay/aws/wiki/Scripting-with-%22aws%22 ?

timkay commented 10 years ago

Unfortunately, SQS added the --wait option only recently, so there is confusion between it and the --wait option that was already in "aws". To use long polling, you want --wait 30, without the equal sign. Then, SQS will wait up to that amount of time for a message to arrive. (Using --wait=30 is used by other AWS services.)

I looked closer at the region thing. The code in question is a call out to your code, which might have nothing to do with "aws". If you want region information there, add the region setting to that command line, or else put it in the .awsrc file.

Please let me know if this advise works for you. Otherwise, we'll keep at it.

nibynool commented 10 years ago

Hi again, Thanks for the info about the wait option... I will implement this when I get to the office.

In relation to the region issue, I have the region on the command line, but when I add the -v option I can see that it is not passed to the dm call... I'll do some further investigation in a couple of hours and post some more detail.

timkay commented 10 years ago

Please ignore my previous post... With --exec CMD, the "aws" code receives a message, runs the CMD, and then deletes the message. Obviously it should pass the region along. I'll make that change.

timkay commented 10 years ago

I checked in new code.

See https://github.com/timkay/aws/wiki/SQS-Examples

nibynool commented 10 years ago

Thanks for the update Tim,

I just tried changing my command line for the "--wait" parameter to ./aws --wait 20 --silent --region=us-west-2 recv /123456789012/test-img-proc --exec='system("processMessage", "$body"); $?;' and it didn't work; however, when I changed it to ./aws recv /123456789012/test-img-proc --wait 20 --silent --region=us-west-2 --exec='system("processMessage", "$body"); $?;' it started working. Perhaps when you next update your docs you could mention that parameter order is important (or do you already do that and I missed it?).

While I was writing this I saw your code mod come through, so I applied a patch to my local copy, cleared my queue, fired everything up, and it is now working perfectly.

Thanks for the rapid response to these issues!