Skip to main content

More Info:

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

Risk Level

Medium

Address

Security

Compliance Standards

  • APRA CPS 234 (Australia)
  • BSI C5 (Germany)
  • Brazil LGPD
  • CCPA / CPRA (California)
  • CIS Critical Security Controls v8
  • CMMC 2.0
  • CSA Cloud Controls Matrix v4
  • DPDPA
  • Digital Operational Resilience Act (EU)
  • HIPAA
  • ISO/IEC 27017
  • ISO/IEC 27018
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIS2 Directive
  • NIST CSF
  • NIST SP 800-171
  • NYDFS 23 NYCRR 500
  • PCI
  • SOC2
  • SWIFT Customer Security Controls Framework
  • Sarbanes-Oxley IT General Controls
  • UK NCSC Cyber Assessment Framework

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration “Lambda Should Have Access To VPC-only Resources” for AWS using AWS console, you can follow the below steps:
  1. Go to the AWS Lambda console.
  2. Select the Lambda function that needs to access VPC-only resources.
  3. Click on the “Configuration” tab.
  4. Scroll down to the “Network” section.
  5. Click on “Edit”.
  6. Select the VPC that has the required resources.
  7. Select the subnets that the Lambda function needs to access.
  8. If required, select the security groups that the Lambda function needs to access.
  9. Click on “Save” to apply the changes.
By following the above steps, the Lambda function will have access to VPC-only resources.

To remediate the misconfiguration “Lambda Should Have Access To VPC-only Resources” in AWS using AWS CLI, you can follow the below steps:
  1. Open the AWS CLI on your local machine or EC2 instance.
  2. Run the following command to create a new VPC configuration file:
Here, replace <CIDR_BLOCK> with the CIDR block range you want to use for your VPC.
  1. Run the following command to create a new subnet within the VPC:
Here, replace <VPC_ID> with the ID of the VPC you created in step 2 and <SUBNET_CIDR_BLOCK> with the CIDR block range you want to use for your subnet.
  1. Run the following command to create a new security group for the Lambda function:
Here, replace <SECURITY_GROUP_NAME> with the name you want to give your security group, <SECURITY_GROUP_DESCRIPTION> with a brief description of the security group, and <VPC_ID> with the ID of the VPC you created in step 2.
  1. Run the following command to modify the security group to allow inbound traffic from the VPC:
Here, replace <SECURITY_GROUP_ID> with the ID of the security group you created in step 4 and <SUBNET_CIDR_BLOCK> with the CIDR block range of the subnet you created in step 3.
  1. Run the following command to create a new execution role for the Lambda function:
Here, replace <ROLE_NAME> with the name you want to give your execution role and trust-policy.json with the file path to your trust policy document.
  1. Run the following command to attach the necessary policies to the execution role:
Here, replace <ROLE_NAME> with the name of the execution role you created in step 6.
  1. Run the following command to update the Lambda function to use the VPC and security group:
Here, replace <FUNCTION_NAME> with the name of the Lambda function you want to update, <SUBNET_ID> with the ID of the subnet you created in step 3, <SECURITY_GROUP_ID> with the ID of the security group you created in step 4, and <ROLE_ARN> with the ARN of the execution role you created in step 6.
  1. Run the following command to test the Lambda function to ensure it has access to VPC-only resources:
Here, replace <FUNCTION_NAME> with the name of the Lambda function you updated in step 8.These steps should remediate the misconfiguration “Lambda Should Have Access To VPC-only Resources” in AWS using AWS CLI.
To remediate the Lambda function not having access to VPC-only resources in AWS, you can follow the below steps:
  1. Open the AWS Management Console and navigate to the Lambda service page.
  2. Locate the Lambda function that needs to access VPC-only resources and click on it.
  3. Click on the “Configuration” tab and scroll down to the “VPC” section.
  4. Click on the “Edit” button to edit the VPC configuration.
  5. Select the VPC that the Lambda function needs to access and select at least one subnet in each Availability Zone.
  6. Select the security groups that allow access to the resources needed by the Lambda function.
  7. Click on the “Save” button to save the updated VPC configuration.
Now, the Lambda function will have access to VPC-only resources.Here is a sample Python code to create a Lambda function with access to VPC-only resources:
Make sure to attach the appropriate VPC and security group to the Lambda function while creating it.
Replace:
  • FUNCTION_NAME with your Lambda function name.
  • INDEX.HANDLER and RUNTIME with your real handler and runtime.
  • aws_subnet.PRIVATE_SUBNET_1/2 with your actual private subnet resources/IDs in the target VPC.
  • aws_security_group.LAMBDA_SG with the security group you want the Lambda to use.
  • LAMBDA_EXEC_ROLE_NAME with your Lambda execution role name.
This change updates the Lambda configuration in place (no forced replacement of the function), but it will create and attach ENIs in your VPC when the function runs. Ensure those subnets have a route to a NAT Gateway if the function needs internet access.Verification: terraform plan should show an in-place update to aws_lambda_function.FUNCTION_NAME with vpc_config.subnet_ids and vpc_config.security_group_ids changing from [] (or null) to the specified subnet and security group IDs, plus creation/attachment of the IAM role policy if it did not exist.

Additional Reading: