CloudWatch Filter Pattern
When an AWS lambda crashes it doesn't get a chance to leave an exception. We will use filter patterns on AWS CloudWatch logs to trigger backup processing when lambdas fail.
[1] Error Generating Lambda
{
"input_bucket": "noaa-wcsd-pds",
"input_key": "data/raw/Henry_B._Bigelow/HB20ORT/EK60/D20200225-T163738.raw",
"output_bucket": "noaa-wcsd-pds-index",
"output_key": "data/raw/Henry_B._Bigelow/HB20ORT/EK60/D20200225-T163738.zarr"
}import logging
import os
import time
import random
logging.basicConfig(level=logging.DEBUG)
logger=logging.getLogger(__name__)
def test_out_of_time():
random_number = random.randint(2, 5)
logger.info(f"Testing out of time, random_number is: {random_number}")
time.sleep(random_number)
def test_out_of_memory():
s = []
logger.info(f"Testing out of memory")
for i in range(1000):
for j in range(1000):
for k in range(1000):
s.append("More")
def lambda_handler(event: dict, context: dict) -> dict:
print(f"Lambda function ARN: {context.invoked_function_arn}")
print(f"CloudWatch log stream name: {context.log_stream_name}")
print(f"CloudWatch log group name: {context.log_group_name}")
print(f"Lambda Request ID: {context.aws_request_id}")
print(f"Lambda function memory limits in MB: {context.memory_limit_in_mb}")
print(f"Lambda time remaining in MS: {context.get_remaining_time_in_millis()}")
#
logger.setLevel(logging.DEBUG)
logger.info(f"_HANDLER: {os.environ['_HANDLER']}")
logger.info(f"AWS_EXECUTION_ENV: {os.environ['AWS_EXECUTION_ENV']}")
AWS_LAMBDA_FUNCTION_MEMORY_SIZE = os.environ['AWS_LAMBDA_FUNCTION_MEMORY_SIZE'];
print(f"AWS_LAMBDA_FUNCTION_MEMORY_SIZE: {AWS_LAMBDA_FUNCTION_MEMORY_SIZE}")
#
input_bucket = event["input_bucket"] # 'noaa-wcsd-pds'
print(f"input bucket: {input_bucket}")
logger.info(f"input bucket: {input_bucket}")
input_key = event["input_key"] # 'data/raw/Henry_B._Bigelow/HB20ORT/EK60/D20200225-T163738.raw'
print(f"input key: {input_key}")
logger.info(f"input key: {input_key}")
output_bucket = event["output_bucket"] # 'noaa-wcsd-zarr-pds'
print(f"output bucket: {output_bucket}")
output_key = event["output_key"]
print(f"output key: {output_key}") # data/raw/Henry_B._Bigelow/HB20ORT/EK60/D20200225-T163738.zarr
#
test_out_of_time();
#test_out_of_memory();
#
logger.info("This is a sample INFO message.. !!")
logger.debug("This is a sample DEBUG message.. !!")
logger.error("This is a sample ERROR message.... !!")
logger.critical("This is a sample 6xx error message.. !!")[2] Testing Cloudwatch
Order of events during processing
Last updated