Skip to main content
MEDIUMLambdaCost Optimization

Lambda Memory Optimization

lambda-memory-optimization

What this rule checks

Detects Lambda functions with suboptimal memory configuration.

How to fix it

  1. 1Use AWS Lambda Power Tuning to find optimal memory
  2. 2Consider cost vs performance tradeoffs
Flagged`memorySize: 2048` sets `MemorySize` above the 1024 MB threshold the check watches. Over-provisioned memory is billed on every invocation, so the rule warns about the cost (MEDIUM, Cost Optimization).
import * as lambda from 'aws-cdk-lib/aws-lambda';

// inside your Stack
new lambda.Function(this, 'Fn', {
  runtime: lambda.Runtime.NODEJS_22_X,
  handler: 'index.handler',
  code: lambda.Code.fromInline('exports.handler = async () => {};'),
  memorySize: 2048,
});
FixedA `memorySize` of 512 MB is at or below the 1024 MB threshold, so the high-memory warning does not fire. Right-size the value against observed usage rather than defaulting high.
import * as lambda from 'aws-cdk-lib/aws-lambda';

// inside your Stack
new lambda.Function(this, 'Fn', {
  runtime: lambda.Runtime.NODEJS_22_X,
  handler: 'index.handler',
  code: lambda.Code.fromInline('exports.handler = async () => {};'),
  memorySize: 512,
});

CDK Insights pinpoints the exact file and line in your CDK source for every finding, so you can jump straight to the fix.

Affected resource types

AWS::Lambda::Function

AWS documentation

Read the AWS guidance

Intentional? Suppress this finding

Sometimes a flag is deliberate โ€” a genuinely public endpoint, say. You can dismiss lambda-memory-optimization and the reason is kept in the report, not silently hidden.

In .cdk-insights.json:

{
  "ignoreRules": [
    { "id": "lambda-memory-optimization", "reason": "Why this is intentional" }
  ]
}

Or inline in your CDK code:

Validations.of(scope).acknowledge({
  id: 'cdk-insights::lambda-memory-optimization',
  reason: 'Why this is intentional',
});

Use the rule ID lambda-memory-optimization shown above โ€” not the CDK-* ID from SARIF / GitHub code scanning. To dismiss every finding on one construct instead, use ignorePaths. Suppression docs โ†’

Catch this in your stack

$ npx cdk-insights scan

CDK Insights runs this and 118+ other rules locally against your synthesised CDK app โ€” free, no account, your code never leaves your machine.

More Lambda rules