Skip to main content
MEDIUMIAMReliability

Compute Reference Without IAM Permissions

TL-PERM-001

What this rule checks

A Lambda function or ECS task definition references an in-template resource (DynamoDB table, S3 bucket, SQS queue, SNS topic, Kinesis stream, secret, event bus, state machine) through an environment variable, but its execution role grants no action in that service namespace on it โ€” the forgotten-grant footgun. Calls fail with AccessDenied at runtime. Fires only on zero coverage; never guesses specific missing actions.

How to fix it

  1. 1Grant access with the CDK L2 grant methods, e.g. table.grantReadWriteData(fn), bucket.grantReadWrite(fn), queue.grantSendMessages(fn), secret.grantRead(fn)
  2. 2Or add an IAM policy statement to the execution role with the actions your code calls, scoped to the referenced resource
  3. 3If the reference is intentional without direct API access, suppress with ignoreRules: ["TL-PERM-001"]
FlaggedThe function receives the table name through an environment variable, but no grant was ever made โ€” its execution role has zero dynamodb: permissions. The stack synthesizes and deploys cleanly, then every call to the table fails with AccessDenied at runtime.
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as lambda from 'aws-cdk-lib/aws-lambda';

const table = new dynamodb.Table(this, 'Orders', {
  partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
});

new lambda.Function(this, 'Api', {
  runtime: lambda.Runtime.NODEJS_20_X,
  handler: 'index.handler',
  code: lambda.Code.fromInline('exports.handler = async () => {};'),
  environment: { TABLE_NAME: table.tableName },
});
Fixedtable.grantReadWriteData(api) materializes an IAM policy on the function's role scoped to the table, so the role now covers the referenced resource and the finding clears.
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as lambda from 'aws-cdk-lib/aws-lambda';

const table = new dynamodb.Table(this, 'Orders', {
  partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
});

const api = new lambda.Function(this, 'Api', {
  runtime: lambda.Runtime.NODEJS_20_X,
  handler: 'index.handler',
  code: lambda.Code.fromInline('exports.handler = async () => {};'),
  environment: { TABLE_NAME: table.tableName },
});

table.grantReadWriteData(api);

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::FunctionAWS::ECS::TaskDefinitionAWS::IAM::Role

AWS documentation

Read the AWS guidance

Intentional? Suppress this finding

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

In .cdk-insights.json:

{
  "ignoreRules": [
    { "id": "TL-PERM-001", "reason": "Why this is intentional" }
  ]
}

Or inline in your CDK code:

Validations.of(scope).acknowledge({
  id: 'cdk-insights::TL-PERM-001',
  reason: 'Why this is intentional',
});

Use the rule ID TL-PERM-001 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 131+ other rules locally against your synthesised CDK app โ€” free, no account, your code never leaves your machine.

More IAM rules