-
-
Save civic/87a10c1110c9416c295c96948995da7c to your computer and use it in GitHub Desktop.
consumer-try-except.py
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) | |
try: | |
if msg['no'] == 5: | |
raise ValueError("Something wrong.") | |
log.info("Consumed a message: no=[%s], messageId=[%s], ApproximateReceiveCount=[%s]", | |
msg['no'], message_id, approximateReceiveCount) | |
except Exception as e: | |
log.info("Error->Skip: 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