Control: Are there any lambda functions with excessive timeout?
Description
Excessive timeouts result in retries and additional execution time for the function, incurring request charges and billed duration. The control checks for functions with a timeout rate of more than 10% a day in one of the last 7 days.
Usage
Run the control in your terminal:
powerpipe control run aws_thrifty.control.lambda_function_excessive_timeoutSnapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run aws_thrifty.control.lambda_function_excessive_timeout --shareSteampipe Tables
SQL
with lambda_duration as (  select    name,    avg(average:: numeric) as avg_duration  from    aws_lambda_function_metric_duration_daily  where    date_part('day', now() - timestamp) <=7  group by    name)select  arn as resource,  case    when avg_duration is null then 'error'    when ((timeout :: numeric*1000) - avg_duration)/(timeout :: numeric*1000) > 0.1 then 'alarm'    else 'ok'  end as status,  case    when avg_duration is null then 'CloudWatch lambda metrics not available for ' || title || '.'    else title || ' Timeout of ' || timeout::numeric*1000 || ' milliseconds is ' || round(((timeout :: numeric*1000)-avg_duration)/(timeout :: numeric*1000)*100,1) || '% more as compared to average of ' || round(avg_duration,0) || ' milliseconds.'  end as reason        , region, account_idfrom  aws_lambda_function f  left join lambda_duration as d on f.name = d.name;