Control: 4.2 Ensure Cloudwatch Lambda insights is enabled
Description
Ensure that Amazon CloudWatch Lambda Insights is enabled for your Amazon Lambda functions for enhanced monitoring.
Amazon CloudWatch Lambda Insights allows you to monitor, troubleshoot, and optimize your Lambda functions. The service collects system-level metrics and summarizes diagnostic information to help you identify issues with your Lambda functions and resolve them as soon as possible. CloudWatch Lambda Insights collects system-level metrics and emits a single performance log event for every invocation of that Lambda function.
Remediation
From the Console:
- Login to AWS Console using https://console.aws.amazon.com/lambda/.
 - Click 
Functions. - Click on the name of the function.
 - Click on the 
Configuration tab. - Click on 'Monitoring and operations tools'.
 - In the Monitoring and operations tools section click 
Editto update the monitoring configuration. - In the CloudWatch Lambda Insights section click the 
Enhanced monitoringbutton to enable. Note - When you enable the feature using the AWS Management Console, Amazon Lambda adds the required permissions to your function's execution role. - Click Save.
 - Repeat steps 2-8 for each Lambda function within the current region that fails the Audit.
 - Then repeat the Audit process for all other regions.
 
Usage
Run the control in your terminal:
powerpipe control run aws_compliance.control.cis_compute_service_v100_4_2Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run aws_compliance.control.cis_compute_service_v100_4_2 --shareSQL
This control uses a named query:
select  arn as resource,  case    when exists (      select 1      from jsonb_array_elements(layers) as l      where l ->> 'Arn' like '%:layer:LambdaInsightsExtension:%'    ) then 'ok'    else 'alarm'  end as status,  case    when exists (      select 1      from jsonb_array_elements(layers) as l      where l ->> 'Arn' like '%:layer:LambdaInsightsExtension:%'    ) then title || ' CloudWatch Insights enabled.'    else title || ' CloudWatch Insights disabled.'  end as reason    , region, account_idfrom  aws_lambda_function;