Detect noncompliant Lambda runtimes in your environment
Tags: aws, security, serverless
Published: 2021-01-19 10:24:40

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ive32fkcsckqe6mvkgv7.png)

A few days ago the Python Software Foundation (PSF) annouced that Python 2.7.18 was the final release of Python 2. With it's release, the PSF states that “As of January 1st, 2020 no new bug reports, fixes, or changes will be made to Python 2, and Python 2 is no longer supported.” In addition, AWS announced that Lambda will only support Python 2.7 until June 1, 2021. This phenomenon will overtake us again and again with other programming languages. Furthermore, it is advisable to always keep your Lambdas up to date with the latest programming languages versions in order to prevent security gaps and to gain the latest features.
Here is a simple way to find out which lambdas in your environment are not compliant with the latest programming languages.

Since we want to use an AWS Config Rule to detect not compliant Lambda runtimes - we need to ensure that AWS Config is activated in your AWS Region. There are multiple ways to enable Config - you can use Infrastructure as Code ([Terraform](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/config_configuration_recorder) - [CloudFormation](https://s3.amazonaws.com/cloudformation-stackset-sample-templates-us-east-1/EnableAWSConfig.yml) - CDK) or just do it using the Console ⛔️ Not a best practice ⛔️.

After we have enabled Config - we are able to deploy the AWS managed Config rule that checks for Lambda function settings eg. runtime. Here is a CloudFormation template to deploy the managed rule. If you want to adjust the compliant Lambda runtimes you just need to update the parameter `CompliantLambdaRuntimes`.

</br>

```yaml
# Author: David Krohn
AWSTemplateFormatVersion: 2010-09-09
#-----------------------------------------------------------------------------
#Parameters
#-----------------------------------------------------------------------------
Parameters:

  CompliantLambdaRuntimes:
    Type: String
    Default: python3.6,nodejs12.x
    Description: CompliantLambdaRuntimes (Commaseperated)

#-----------------------------------------------------------------------------
#Resources 
#-----------------------------------------------------------------------------
Resources:
  CheckForNonCompliantLambdaRuntimes:
    Type: AWS::Config::ConfigRule
    Properties:
        ConfigRuleName: Lambda-NonCompliantRuntimes
        Description: Checks that the AWS Lambda function settings for runtime, role, timeout, and memory size match the expected values.
        InputParameters:
          runtime: !Ref CompliantLambdaRuntimes
        Source:
            Owner: AWS
            SourceIdentifier: LAMBDA_FUNCTION_SETTINGS_CHECK
```

</br>
</br>

If you want to deploy the managed rule using the Console you just need to go to `AWS Config` > `Rules` > `Add rule` and select the rule `lambda-function-settings-check`. 
This rule will help us to identify noncompliant Lambda runtimes. We just need to pass compliant runtimes comma-seperated to the runtime parameter eg.: `python3.6,nodejs12.x`. At the end the result in the AWS Console would look like this:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/x3qwtc107mi222dd0vz1.png)