Lambda Variable Runtime
lambda-runtime-pinned-latest
What this rule checks
Detects Lambda functions using a variable runtime (Runtime.NODEJS_LATEST or useLatestRuntimeVersion) that resolves to the newest runtime at synth time, causing silent in-place runtime upgrades on the next deploy after a CDK bump.
How to fix it
- 1Pin an explicit runtime (e.g. Runtime.NODEJS_22_X)
- 2Or set useLatestRuntimeVersion: false on NodejsFunction
- 3Treat runtime upgrades as a deliberate, reviewed change
import * as lambda from 'aws-cdk-lib/aws-lambda';
// Variable runtime: resolves to whatever the newest Node.js runtime is at
// synth time, so a CDK upgrade silently changes the deployed runtime.
new lambda.Function(this, 'Fn', {
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
code: lambda.Code.fromInline('exports.handler = async () => {};'),
});import * as lambda from 'aws-cdk-lib/aws-lambda';
// Explicitly pinned runtime โ upgrades are a deliberate, reviewed change.
new lambda.Function(this, 'Fn', {
runtime: lambda.Runtime.NODEJS_22_X,
handler: 'index.handler',
code: lambda.Code.fromInline('exports.handler = async () => {};'),
});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::FunctionIntentional? Suppress this finding
Sometimes a flag is deliberate โ a genuinely public endpoint, say. You can dismiss lambda-runtime-pinned-latest and the reason is kept in the report, not silently hidden.
In .cdk-insights.json:
{
"ignoreRules": [
{ "id": "lambda-runtime-pinned-latest", "reason": "Why this is intentional" }
]
}Or inline in your CDK code:
Validations.of(scope).acknowledge({
id: 'cdk-insights::lambda-runtime-pinned-latest',
reason: 'Why this is intentional',
});Use the rule ID lambda-runtime-pinned-latest 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 scanCDK Insights runs this and 118+ other rules locally against your synthesised CDK app โ free, no account, your code never leaves your machine.