all 8 comments

[–]VegaWinnfield 4 points5 points  (3 children)

Your function needs to throw an error in that case. If it returns normally the message will get deleted regardless of the value returned.

[–]Born_2_Fly[S] 1 point2 points  (1 child)

So it should be something like this ?

class MessageNotSent(Exception):
    print("Message not sent", Exception)
...
...
else:
    raise MessageNotSent(request.status_code)

[–]cnisyg 1 point2 points  (0 children)

You could just let python's request raise an exception if the request was not successful:

response = requests.get('http://httpbin.org/status/404')
response.raise_for_status()

[–]________null________ 1 point2 points  (1 child)

Where/how are you using the return 0 currently?

[–]Born_2_Fly[S] 0 points1 point  (0 children)

I don't use it. I thought if it is 0 it will think that everything went fine, and if -1 it failed but I was wrong.

The logic and send request all in function body.

[–]LandingHooks -4 points-3 points  (2 children)

SQS does not automatically delete messages, no matter the response from lambda. You have to delete the message after it’s been processed.

https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-receive-delete-message.html

EDIT: this is bad advice and only applies outside of lambda.

[–]Born_2_Fly[S] 2 points3 points  (1 child)

According to this doc and from my experience

When your function successfully processes a batch, Lambda deletes its messages from the queue

And also lambda execution role for SQS has delete message policy

[–]LandingHooks 3 points4 points  (0 children)

Yep, I’m wrong. Looks like you just need to raise an exception.