in packages/data-audit/src/audit/aws-lambda.ts [16:55]
async function numberOfLambdaFunctionsForAwsAccount(
stage: string,
accountId: string,
region: string,
): Promise<number> {
const client = new LambdaClient(
// Use the same IAM Role that CloudQuery uses to eliminate permission issues being the cause of data difference
awsClientConfig(
stage,
`arn:aws:iam::${accountId}:role/cloudquery-access`,
region,
),
);
const functions: FunctionConfiguration[] = [];
for await (const page of paginateListFunctions(
{ client, pageSize: 50 },
{},
)) {
functions.push(...(page.Functions ?? []));
// (attempt to) avoid rate limiting by sleeping for 3 seconds between pages
await sleep(3000);
}
const total = functions.length;
console.log(
JSON.stringify({
message: `Found ${total} lambda functions in region ${region} for account ${accountId}`,
account: accountId,
region,
client: `${accountId}:${region}`,
total,
}),
);
return total;
}