Skip to content

Instantly share code, notes, and snippets.

@civic
Created January 22, 2023 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save civic/26efee7b9c49fd35e23d52dda50d2ef2 to your computer and use it in GitHub Desktop.
Save civic/26efee7b9c49fd35e23d52dda50d2ef2 to your computer and use it in GitHub Desktop.
consumer-with-exception
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