def lambda_handler()

in lambda.py [0:0]


def lambda_handler(event, context):
    
    global NAME
    client = boto3.client('network-firewall')
    
    # Set up logging
    if len(logging.getLogger().handlers) > 0:
        logging.getLogger().setLevel(logging.ERROR)
    else:
        logging.basicConfig(level=logging.DEBUG)
    
    # SNS message notification event when the ip ranges document is rotated
    message = json.loads(event['Records'][0]['Sns']['Message'])
    
    # Get the updated IP ranges from the link in the SNS message
    ip_ranges = json.loads(get_ip_groups_json(message['url']))
    cf_ranges = get_ranges_for_service(ip_ranges, SERVICE)
    
    # Try to create the new rule group. If it exists, get the update token and update the list.
    try:
        create_rule_group(NAME, cf_ranges)
    except client.exceptions.InvalidRequestException:
        updateToken = get_update_token(NAME)
        update_rule_group(NAME, cf_ranges, updateToken)