Skip to content

Instantly share code, notes, and snippets.

@kuharan
Last active April 19, 2022 17:13
Show Gist options
  • Save kuharan/c2bfddac7bd8dc5702f6eec31729fb48 to your computer and use it in GitHub Desktop.
Save kuharan/c2bfddac7bd8dc5702f6eec31729fb48 to your computer and use it in GitHub Desktop.
import signal
def timeout_handler(_signal, _frame):
global unprocess_bucket
global unprocess_file
logger.info("Time exceeded! Creating Unprocessed File.")
session = boto3.Session()
s3_client = session.client(service_name="s3")
s3_client.put_object(
Body="",
Bucket=unprocess_bucket,
Key=unprocess_file.replace(
unprocess_file.split("/")[1], "doc_pdf/unprocessed_files"
),
)
signal.signal(signal.SIGALRM, timeout_handler)
def lambda_handler(event, context):
signal.alarm(int(context.get_remaining_time_in_millis() / 1000) - 15)
## rest of the code ##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment