Enable VPC Access for Lambda Functions

Trend Micro Cloud One™ – Conformity is a continuous assurance tool that provides peace of mind for your cloud infrastructure, delivering over 750 automated best practice checks.

Risk level: Medium (should be achieved)
Rule ID: Lambda-007

Ensure that your Amazon Lambda functions have access to VPC-based resources such as Amazon Redshift data warehouses, Amazon ElastiCache clusters, RDS database instances, and service endpoints that are only accessible from within a particular Virtual Private Cloud (VPC).

This rule can help you with the following compliance standards:

  • PCI
  • APRA
  • MAS

For further details on compliance standards supported by Conformity, see here.

This rule resolution is part of the Conformity Security & Compliance tool for AWS.

Security

Based on your application requirements, you can associate your Amazon Lambda functions with the appropriate Virtual Private Cloud (VPC). For example, to access the cloud resources provisioned inside a private VPC, you must provide additional VPC-specific configuration information that includes the VPC subnet IDs and security group IDs. Amazon Lambda uses this configuration information to set up Elastic Network Interfaces (ENIs) that enable your functions to connect securely to other cloud resources available within your private VPC.


Audit

To determine if your Amazon Lambda functions are associated with Virtual Private Clouds (VPCs), perform the following operations:

Using AWS Console

01 Sign in to the AWS Management Console.

02 Navigate to Amazon Lambda console at https://console.aws.amazon.com/lambda/.

03 In the left navigation panel, under AWS Lambda, choose Functions.

04 Click on the name (link) of the function that you want to examine.

05 Select the Configuration tab and choose VPC from the left menu.

06 In the VPC section, check the configuration settings of the Virtual Private Cloud (VPC) network associated with the selected function. If there are no VPC configuration settings available in the VPC section, the selected Amazon Lambda function is not connected to a Virtual Private Cloud (VPC) network, therefore the function can't access your VPC resources.

07 Repeat steps no. 4 – 6 for each Lambda function available within the current AWS region.

08 Change the AWS cloud region from the console navigation bar and repeat the Audit process for other regions.

Using AWS CLI

01 Run list-functions command (OSX/Linux/UNIX) to list the name of each Amazon Lambda function available in the selected AWS cloud region:

aws lambda list-functions
	--region us-east-1
	--output table
	--query 'Functions[*].FunctionName'

02 The command output should return a table with the requested function name(s):

---------------------
|   ListFunctions   |
+-------------------+
|   cc-sqs-poller   |
|   cc-s3-logging   |
|   s3-get-object   |
+-------------------+

03 Run get-function command (OSX/Linux/UNIX) using the name of the Amazon Lambda function that you want to examine as the identifier parameter and custom query filters to describe the ID of the Virtual Private Cloud (VPC) associated with the selected function:

aws lambda get-function
  --region us-east-1
  --function-name cc-sqs-poller
  --query 'Configuration.VpcConfig.VpcId'

04 The command output should return the VPC ID requested – if the function is configured to access a VPC network, null – if the function has not yet been associated with a VPC, or an empty string (i.e. "") – if the function was associated at one point with a VPC network:

null

If the get-function command output returns null or an empty string (i.e. ""), the selected Amazon Lambda function is not connected to a Virtual Private Cloud (VPC) network, therefore the function can't access your VPC-specific resources.

05 Repeat step no. 3 and 4 for each Lambda function available in the selected AWS region.

06 Change the AWS region by updating the --region command parameter value and repeat steps no. 1 – 5 to perform the Audit process for other regions.

Remediation / Resolution

To associate an existing Amazon Lambda function with a Virtual Private Cloud (VPC), you have to update your function's network configuration. In order to do that, you simply select one of your VPCs and identify the relevant subnets and security groups. Amazon Lambda makes use of this information to set up the Elastic Network Interfaces (ENIs) and private IP addresses (taken from the subnet(s) that you specified) so that your function has access to the cloud resources within the selected VPC. To update the network configuration for your Amazon Lambda functions, perform the following operations:

Using AWS Console

01 Sign in to the AWS Management Console.

02 Navigate to Amazon Lambda console at https://console.aws.amazon.com/lambda/.

03 In the left navigation panel, under AWS Lambda, choose Functions.

04 Click on the name of the function that you want to reconfigure.

05 Select the Configuration tab and choose VPC from the left menu.

06 In the VPC section, choose Edit to change the network configuration for the selected function.

07 On the Edit VPC configuration page, perform the following actions:

  1. Select the ID of the VPC network that you want to associate with the selected function from the VPC dropdown list.
  2. Choose the VPC subnets that Amazon Lambda will use to set up your VPC configuration from the Subnets dropdown list. Select at least two VPC subnets so that Amazon Lambda can execute your function in high-availability mode.
  3. Select the security group(s) that Amazon Lambda service will use to set up your VPC network configuration from the Security groups dropdown list. When you connect a function to a VPC network in your AWS account, it does not have access to the Internet unless your VPC provides Internet access. To give your function access to the Internet, route outbound traffic to a NAT Gateway in a public subnet.
  4. Choose Save to apply the network configuration changes and connect the selected Amazon Lambda function to your VPC network.

08 Repeat steps no. 4 – 7 to update the network configuration for each Amazon Lambda function available within the current AWS region.

09 Change the AWS cloud region from the navigation bar and repeat the Remediation process for the other regions.

Using AWS CLI

01 Run update-function-configuration command (OSX/Linux/UNIX) using the name of the Amazon Lambda function that you want to reconfigure as the identifier parameter, to update the function's network configuration in order to connect the function to a Virtual Private Cloud (VPC) network. when you connect a Lambda function to a VPC network, the function's access to the Internet can be made only through that VPC network:

aws lambda update-function-configuration
  --region us-east-1
  --function-name cc-sqs-poller
  --vpc-config SubnetIds="subnet-abcd1234","subnet-1234abcd",SecurityGroupIds="sg-0abcd1234abcd1234"

02 The command output should return the metadata available for the reconfigured function:

{
  "FunctionName": "cc-sqs-poller",
  "FunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:cc-sqs-poller",
  "Runtime": "python3.7",
  "Role": "arn:aws:iam::123456789012:role/service-role/cc-sqs-poller-role-abcdabcd",
  "Handler": "lambda_function.lambda_handler",
  "CodeSize": 550,
  "Timeout": 45,
  "MemorySize": 1024,
  "LastModified": "2021-08-29T10:00:00.000+0000",
  "Version": "$LATEST",
  "VpcConfig": {
    "SubnetIds": [
      "subnet-abcd1234",
      "subnet-1234abcd"
    ],
    "SecurityGroupIds": [
      "sg-0abcd1234abcd1234"
    ],
    "VpcId": "vpc-abcdabcd"
  },
  "TracingConfig": {
    "Mode": "PassThrough"
  },
  "RevisionId": "abcdabcd-1234-abcd-1234-abcd1234abcd",
  "Layers": [
    {
      "Arn": "arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:12",
      "CodeSize": 4351068
    }
  ],
  "State": "Active",
  "LastUpdateStatus": "Successful",
  "PackageType": "Zip"
}

03 Repeat steps no. 1 and 2 to update the network configuration for each Amazon Lambda function available in the selected AWS region.

04 Change the AWS cloud region by updating the --region command parameter value and repeat steps no. 1 – 3 to perform the Remediation process for other regions.

References

Publication date Mar 16, 2019

Unlock the Remediation Steps


Free 30-day Trial

Automatically audit your configurations with Conformity
and gain access to our cloud security platform.

Confirmity Cloud Platform

No thanks, back to article

You are auditing:

Enable VPC Access for Lambda Functions

Risk level: Medium