AWS

Tutorials

List Lambdas Across AWS Accounts and Monitor Health Events Like Recursive Loops

AWS Lambda Functions are a fundamental component of building serverless applications on AWS. However, managing and monitoring these functions across multiple AWS accounts can be complex, especially when dealing with potential issues like recursive loops and health events. This blog post will guide you through using the aws_lambda_functions, aws_health_events, aws_health_event_details and aws_health_affected_entities tables to monitor your AWS Lambda functions and identify potential health issues.

To get started, download the CloudQuery CLI and set up your CloudQuery configuration file by following the AWS Source Integration documentation. Sync your AWS Lambda functions and health events data using CloudQuery’s AWS Source Integration to any destination available in our destination integrations. Our most popular destination integration is PostrgreSQL, so in the query examples below, we’ll use the PostgreSQL Destination Integration. Ensure that you add aws_lambda_functions, aws_health_events, aws_health_event_details, and aws_health_affected_entities tables to the list of tables being synced.
Note that the AWS Health API requires your account to have a business plan, so these tables can only be synced if you do.

Listing Lambda Functions

The aws_lambda_functions table contains data about your Lambda functions, including configuration, tags, and code details. To get a quick view of your lambda functions, you can use the following query:

SELECT
account_id,
arn,
region,
configuration->>'FunctionName' AS function_name,
configuration->>'State' AS function_state,
configuration->>'role' AS function_role,
configuration->>'Runtime' AS runtime,
configuration->>'CodeSize' AS code_size,
configuration->>'MemorySize' AS memory_size,
configuration->'EphemeralStorage'->>'Size' as ephemeral_storage_size,
tags
FROM
aws_lambda_functions;

To understand how many Lambdas are associated with each account, you can run this query:

SELECT
account_id,
COUNT(DISTINCT arn) AS lambda_function_count
FROM
aws_lambda_functions
GROUP BY
account_id;

Similarly, you can run the following query to see how many Lambdas are in each AWS region:

SELECT
region,
COUNT(DISTINCT arn) AS lambda_function_count
FROM
aws_lambda_functions
GROUP BY
region;

Understanding the health status of your lambda functions

In this section, you will use aws_health_events and its associated tables with the aws_lambda_functions table to identify Lambda functions with health alerts.
To list all health events for the Lambda service, you can run this query:

SELECT
account_id,
arn,
region,
availability_zone,
start_time,
end_time,
status_code
FROM
aws_health_events
WHERE
service LIKE '%Lambda%';

To understand what are these events, you need to join them with the aws_health_event_details table using _cq_id and _cq_parent_id

SELECT
events.account_id,
events.arn,
events.region,
events.availability_zone,
events.start_time,
events.end_time,
events.status_code,
event_details.event_description,
event_details.event_metadata
FROM
aws_health_events events
INNER JOIN aws_health_event_details event_details ON events._cq_id = event_details._cq_parent_id
WHERE
service LIKE '%Lambda%';

In the queries above, you listed all of your health events and their details. However, if you want to connect these events with Lambda functions, you need to join the aws_lambda_functions table using the aws_health_affected_entities table.

SELECT
lambdas.account_id,
lambdas.arn,
lambdas.region,
lambdas.configuration->>'FunctionName' AS function_name,
lambdas.configuration->>'State' AS function_state,
lambdas.configuration->>'role' AS function_role,
lambdas.configuration->>'Runtime' AS runtime,
lambdas.configuration->>'CodeSize' AS code_size,
lambdas.configuration->>'MemorySize' AS memory_size,
lambdas.configuration->'EphemeralStorage'->>'Size' as ephemeral_storage_size,
lambdas.tags,
events.arn as event_arn,
events.start_time,
events.end_time,
events.status_code as event_status,
event_details.event_description,
event_details.event_metadata,
affected_entities.status_code as entity_status
FROM
aws_lambda_functions lambdas
LEFT JOIN aws_health_affected_entities affected_entities ON lambdas.arn = affected_entities.entity_arn
LEFT JOIN aws_health_events events ON affected_entities._cq_parent_id = events._cq_id
LEFT JOIN aws_health_event_details event_details ON events._cq_id = event_details._cq_parent_id;

Now that you have listed all of your Lambda functions and their events, you can aggregate these to get the event count for each function:

WITH lambda_events AS (
SELECT
lambdas.account_id,
lambdas.arn,
lambdas.region,
lambdas.configuration->>'FunctionName' AS function_name,
lambdas.configuration->>'State' AS function_state,
lambdas.configuration->>'role' AS function_role,
lambdas.configuration->>'Runtime' AS runtime,
lambdas.configuration->>'CodeSize' AS code_size,
lambdas.configuration->>'MemorySize' AS memory_size,
lambdas.configuration->'EphemeralStorage'->>'Size' as ephemeral_storage_size,
lambdas.tags,
events.arn as event_arn,
events.start_time,
events.end_time,
events.status_code as event_status,
event_details.event_description,
event_details.event_metadata,
affected_entities.status_code as entity_status
FROM
aws_lambda_functions lambdas
LEFT JOIN aws_health_affected_entities affected_entities ON lambdas.arn = affected_entities.entity_arn
LEFT JOIN aws_health_events events ON affected_entities._cq_parent_id = events._cq_id
LEFT JOIN aws_health_event_details event_details ON events._cq_id = event_details._cq_parent_id
)
SELECT
account_id,
arn,
region,
COUNT(DISTINCT event_arn) as event_count
FROM
lambda_events
GROUP BY
account_id, arn, region;

Another option is to look for a specific event with specific keywords. For example, if you have enabled recursive loop detection in your AWS account, you can look for Lambda functions that triggered this event:

WITH lambda_events AS (
SELECT
lambdas.account_id,
lambdas.arn,
lambdas.region,
lambdas.configuration->>'FunctionName' AS function_name,
lambdas.configuration->>'State' AS function_state,
lambdas.configuration->>'role' AS function_role,
lambdas.configuration->>'Runtime' AS runtime,
lambdas.configuration->>'CodeSize' AS code_size,
lambdas.configuration->>'MemorySize' AS memory_size,
lambdas.configuration->'EphemeralStorage'->>'Size' as ephemeral_storage_size,
lambdas.tags,
events.arn as event_arn,
events.start_time,
events.end_time,
events.status_code as event_status,
event_details.event_description,
event_details.event_metadata,
affected_entities.status_code as entity_status
FROM
aws_lambda_functions lambdas
LEFT JOIN aws_health_affected_entities affected_entities ON lambdas.arn = affected_entities.entity_arn
LEFT JOIN aws_health_events events ON affected_entities._cq_parent_id = events._cq_id
LEFT JOIN aws_health_event_details event_details ON events._cq_id = event_details._cq_parent_id
)
SELECT
*
FROM
lambda_events
WHERE
event_description->>'latestDescription' LIKE '%recursive loop%';

Using CloudQuery to monitor your AWS Lambda functions and health events across multiple accounts gives you a clear view of your serverless applications’ health and performance. CloudQuery helps you spot potential issues like recursive loops and health alerts. Start syncing your AWS Lambda functions with CloudQuery today and boost your monitoring capabilities.

Ready to enhance your AWS Lambda function monitoring? Try CloudQuery today and gain detailed insights into your serverless applications. Contact us or join our Community to connect with other users and our engineering team, and explore the full potential of CloudQuery.

Try CloudQuery yourself

Self-hosted, open source, and free to start. Or schedule a demo to see the managed version.

Related posts

AWS

Security

Tutorials

Finding AWS Unrestricted Outbound Access in 2026: EC2, Lambda, and Beyond

Find EC2, Lambda, and ECS Fargate resources with unrestricted outbound access in AWS using SQL. Why egress controls still break attack chains in 2026.

Joe Karlsson

Joe Karlsson

May 5, 2026

AWS

Security

Tutorials

AWS IAM Identity Center with Google Workspace as an IdP: 2026 Step-by-Step Guide

Set up AWS IAM Identity Center with Google Workspace: SAML authentication, SCIM user provisioning, and group sync with CLI or ssosync. Updated for 2026.

Joe Karlsson

Joe Karlsson

May 5, 2026

AWS

Cloud Infrastructure

Security

Tutorials

Integrate AbuseIPDB Threat Intelligence with CloudQuery

Enrich your cloud asset inventory with AbuseIPDB threat intelligence to identify public cloud IPs with known abuse reports.

Joe Karlsson

Joe Karlsson

April 20, 2026

AWS

Cloud Infrastructure

Tutorials

How to Query ipinfo.io Data with CloudQuery

Learn how to enrich your cloud asset inventory with ipinfo.io IP geolocation and threat intelligence data using CloudQuery.

Joe Karlsson

Joe Karlsson

April 20, 2026

AWS

Security

Tutorials

AWS IAM Identity Center (Formerly AWS SSO): The Complete 2026 Guide

AWS SSO is now AWS IAM Identity Center. Set it up, configure permission sets, use the AWS CLI, and audit access across accounts with SQL.

Joe Karlsson

Joe Karlsson

April 6, 2026

AWS

Tutorials

AWS Pinpoint Is Being Deprecated: How to Assess Your Migration Scope

AWS Pinpoint reaches end of support October 2026. Query your Pinpoint usage across all accounts to find what needs migrating before the deadline.

Joe Karlsson

Joe Karlsson

March 24, 2026

AWS

Best Practices

Tutorials

CloudQuery Sync Performance: A Practical Troubleshooting Guide

Diagnose why CloudQuery syncs slow down after plugin upgrades, identify expensive tables, and use the CLI command that replaces the tables wildcard.

Joe Karlsson

Joe Karlsson

March 6, 2026

AWS

Security

Tutorials

Set Up AWS CLI with SSO (IAM Identity Center) — Step by Step

Set up AWS CLI v2 with IAM Identity Center in 5 minutes. Covers SSO registration scopes, sso-session config, token refresh, and multi-account profiles.

Yevgeny Pats

Yevgeny Pats

February 25, 2026

AWS

Cloud Infrastructure

Tutorials

AWS Lambda Python 3.9 End-of-Support: Find and Upgrade Every Affected Function

AWS Lambda Python 3.9 security patches stopped Dec 15, 2025. Find every affected function across all accounts with SQL queries and upgrade to 3.12 or 3.13.

Joe Karlsson

Joe Karlsson

February 10, 2026

Own your pipeline.
Own your data.