-
-
Save civic/26efee7b9c49fd35e23d52dda50d2ef2 to your computer and use it in GitHub Desktop.
consumer-with-exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import json | |
log = logging.getLogger(__name__) | |
log.setLevel(logging.DEBUG) | |
def lambda_handler(event, context): | |
for record in event['Records']: | |
message_id = record['messageId'] | |
attributes = record['attributes'] | |
approximateReceiveCount = attributes['ApproximateReceiveCount'] | |
body = record['body'] | |
msg = json.loads(body) | |
if msg['no'] == 5: | |
raise ValueError("Something wrong.") | |
log.info("Consumed a message: no=[%s], messageId=[%s], ApproximateReceiveCount=[%s]", | |
msg['no'], message_id, approximateReceiveCount) | |
log.info("Finish %d records", len(event['Records'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment