Skip to content

Instantly share code, notes, and snippets.

@yogeshnile
Last active April 9, 2022 18:27
Show Gist options
  • Save yogeshnile/830d5685bb2ebb79a91611db6b407ded to your computer and use it in GitHub Desktop.
Save yogeshnile/830d5685bb2ebb79a91611db6b407ded to your computer and use it in GitHub Desktop.
import signal
import boto3
import os
def lambda_handler(event, context):
signal.alarm(int(context.get_remaining_time_in_millis() / 1000) - 1)
signal.signal(signal.SIGALRM, timeout_handler)
# Do other stuff
while True:
pass
def timeout_handler(_signal, _frame):
client = boto3.client('sns')
LAMBDA_NAME = os.environ['AWS_LAMBDA_FUNCTION_NAME']
response = client.publish(
TopicArn = 'string',
Subject = f'{LAMBDA_NAME} getting timeout.',
Message = f'{LAMBDA_NAME} lambda getting timeout please review it.'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment