VAYULearn
Colour theme
Investigate a failure
VAYU Learn

AWS Data Engineering

IAM for Data Engineers: Security Without Breaking Everything

DataForge AWS Data Engineering Series - Blog 3 of 20

AWS Data EngineeringData Architecture & Reliability

The Glue job had been running fine for eight months. Then it started failing every morning at 2:15 AM with AccessDenied: User is not authorized to perform: s3:GetObject.

Nothing had changed in the pipeline code. Nothing had changed in the Glue job configuration. The data engineer spent two hours checking the job script, the S3 bucket policy, the Glue connection settings — all unchanged. The actual cause: a security team rotation had modified the IAM role’s permission boundary as part of an unrelated compliance initiative, silently narrowing what the role could do. Nobody on the data team was notified. Nobody on the security team knew a Glue job depended on that specific role.

This is the defining characteristic of IAM failures in data engineering: the error message tells you what was denied, but almost never tells you why the permission changed or who changed it. You’re debugging a security boundary that lives outside your codebase, outside your version control, and often outside your team’s visibility.

IAM is not a feature you configure once. It’s the access control layer that every single AWS data service depends on — and it fails in ways that look exactly like every other kind of failure until you know what to look for.

Let’s go deep.


TL;DR

IAM controls every API call every AWS data service makes — Glue reading S3, Lambda writing to DynamoDB, Redshift loading from S3, Step Functions invoking Glue. Getting IAM wrong doesn’t crash your pipeline with an obvious error; it produces AccessDenied messages that look like configuration problems, network problems, or data problems depending on where in the call chain the permission was missing. Understanding IAM's actual model — roles, policies, trust relationships, resource-based vs identity-based permissions — is what separates engineers who diagnose these in minutes from engineers who spend hours guessing.

By the end of this article you’ll be able to:

  • Explain the difference between identity-based and resource-based policies and when each applies
  • Configure the exact IAM pattern each AWS data service needs (Glue, Lambda, EMR, Redshift, Step Functions)
  • Diagnose AccessDenied errors systematically instead of by trial and error
  • Apply least-privilege IAM without breaking pipelines that need to actually function

Series context: Every service in Blogs 5 through 17 requires correctly configured IAM to function. This article is the reference you’ll return to when a pipeline fails with a permissions error — which will happen, regardless of how carefully you configure things upfront.

AccessDenied tells you what was denied. It rarely tells you why. Five checks happen before AWS says yes - three explicit denies that override everything, two explicit allows that only matter if nothing denied first. Know the order, diagnose in minutes.

The Core IAM Model: Four Concepts, Not Twenty

IAM has a lot of surface area. Data engineers need four concepts deeply and can treat the rest as reference material.

1. Identity — who or what is making the request
IAM User: a person (rare in production data pipelines)
IAM Role: an identity assumed temporarily by a service or person

2. Policy — a JSON document defining allowed/denied actions
Identity-based policy: attached to a user, group, or role
Resource-based policy: attached to the resource itself (S3 bucket policy)

3. Trust policy — who is allowed to assume a role
Defines which service or account can become this role

4. Permission evaluation — how AWS decides allow or deny
Explicit deny always wins
Otherwise: any applicable allow wins
Default (nothing matches): deny

The concept that trips up most data engineers: a role has two separate policy types attached to it, and they answer two different questions.

Trust policy answers: "WHO can become this role?"
Permission policy answers: "WHAT can this role DO once assumed?"
A Glue job's execution role needs:
Trust policy: "glue.amazonaws.com can assume this role"
Permission policy: "this role can read/write specific S3 paths,
read/write the Glue Catalog, write CloudWatch logs"
Missing the trust policy: Glue can't even start the job
Missing the permission policy: Glue starts the job, then fails
partway through with AccessDenied

These produce completely different failure signatures — which is the first diagnostic branch point covered later in this article.


Identity-Based vs Resource-Based Policies

This distinction is where most IAM confusion for data engineers originates, because both policy types can grant the same permission, and AWS evaluates both.

Identity-based policy (attached to the role):
{

"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-data-lake/raw/*"
}

This says: "This role can GetObject on this S3 path"

Resource-based policy (attached to the S3 bucket):
{

"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::123456789:role/glue-etl-role"},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-data-lake/raw/*"
}
This says: "This specific role can GetObject on this bucket"

The critical rule: both must allow the action for same-account access. If the identity-based policy allows it but the bucket policy explicitly denies it, the request fails. If the bucket policy allows it but the role’s identity-based policy doesn’t grant it, the request also fails.

Where resource-based policies become mandatory, not optional: cross-account access. If a Glue job in Account A needs to read an S3 bucket in Account B, the identity-based policy on the Glue role alone is not sufficient — the bucket policy in Account B must explicitly grant access to the role’s ARN from Account A. This is the single most common cause of “it works in dev, fails in prod” IAM issues when dev and prod are separate AWS accounts (which they should be).


How Permission Evaluation Actually Works

This is the mechanism worth understanding precisely, because “why was this denied” questions almost always trace back to a gap in this evaluation sequence.

Walk through a concrete request: a Glue job attempts to read an object from S3.

Request: Glue role attempts s3:GetObject on
s3://my-data-lake/raw/events/file.parquet

Step 1: Explicit deny check (identity-based policies)
Does any policy attached to the Glue role explicitly DENY
this action on this resource?
→ If yes: DENIED. Stop here. Nothing else matters.
→ If no: continue

Step 2: Explicit deny check (resource-based policy)
Does the S3 bucket policy explicitly DENY this principal
from this action?
→ If yes: DENIED. Stop here.
→ If no: continue

Step 3: Explicit deny check (Service Control Policies / permission
boundaries, if configured at the organization level)
→ If yes: DENIED. Stop here.
→ If no: continue

Step 4: Explicit allow check (identity-based policy)
Does any policy attached to the Glue role explicitly ALLOW
this action on this resource?
→ If yes: proceed to step 5
→ If no: implicit DENY (default)

Step 5: Explicit allow check (resource-based policy, if applicable
— required for cross-account, optional for same-account)
Same-account: identity-based allow alone is sufficient
Cross-account: resource-based allow is REQUIRED in addition

Result: ALLOWED only if no explicit deny fired AND
at least one explicit allow was found

The operational implication: an explicit deny anywhere in the chain overrides every allow, no matter how many policies grant the permission elsewhere. This is by design — it’s how organizations enforce hard security boundaries (like the opening scenario’s permission boundary) that individual teams cannot override even with correctly configured role policies.

Why the opening scenario’s failure was so hard to diagnose: the Glue role’s own policy hadn’t changed. The bucket policy hadn’t changed. The permission boundary — a separate, organization-level constraint that caps what a role can ever do regardless of its own policy — had changed. Permission boundaries are invisible unless you specifically know to check them, because they don’t show up when you review the role’s attached policies.


The IAM Patterns Each AWS Data Service Actually Needs

Generic “IAM tutorials” don’t tell you what a Glue job specifically needs versus what a Lambda function specifically needs. Here’s the reference.

AWS Glue Job Execution Role

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:PutObject", "s3:ListBucket"],
"Resource": [
"arn:aws:s3:::my-data-lake/raw/*",
"arn:aws:s3:::my-data-lake/processed/*",
"arn:aws:s3:::my-data-lake"
]
},
{
"Effect": "Allow",
"Action": [
"glue:GetTable", "glue:GetDatabase",
"glue:CreateTable", "glue:UpdateTable",
"glue:GetPartitions", "glue:BatchCreatePartition"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:/aws-glue/*"
}
]
}

Plus the trust policy allowing glue.amazonaws.com to assume the role.

What’s commonly wrong: teams grant s3:* on the entire bucket "to make it work faster," which means a bug in the job can delete or overwrite data outside its intended scope. The correct pattern scopes S3 permissions to the specific prefixes the job actually reads and writes.

Lambda Execution Role for Event-Driven Pipelines

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::my-data-lake/raw/*"
},
{
"Effect": "Allow",
"Action": ["states:StartExecution"],
"Resource": "arn:aws:states:*:*:stateMachine:my-pipeline"
},
{
"Effect": "Allow",
"Action": ["logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents"],
"Resource": "arn:aws:logs:*:*:*"
}
]
}

The specific Lambda trap: Lambda functions triggered by S3 events need the S3 bucket to have a resource-based policy granting s3:PutBucketNotification permission separately from the Lambda execution role's own permissions. This is configured automatically when you set up the trigger through the console, but Infrastructure-as-Code (CloudFormation/Terraform/CDK) deployments frequently miss this if written by hand.

Redshift COPY Command Role

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:GetObject", "s3:ListBucket"],
"Resource": [
"arn:aws:s3:::my-data-lake/processed/*",
"arn:aws:s3:::my-data-lake"
]
}
]
}

With trust policy allowing redshift.amazonaws.com to assume the role, and the role attached to the Redshift cluster (not passed per-query in most modern configurations).

The specific Redshift trap: the role must be attached to the cluster via IAM Roles configuration in Redshift itself, not just created in IAM. A correctly configured IAM role that was never attached to the cluster produces S3ServiceException: Access Denied on every COPY command — and the error doesn't tell you the role wasn't attached, only that access was denied.

Step Functions State Machine Role

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["glue:StartJobRun", "glue:GetJobRun"],
"Resource": "arn:aws:glue:*:*:job/my-etl-job"
},
{
"Effect": "Allow",
"Action": ["lambda:InvokeFunction"],
"Resource": "arn:aws:lambda:*:*:function:my-function"
}
]
}

The specific Step Functions trap: Step Functions needs permission to invoke every service it orchestrates — it doesn’t inherit permissions from the services it’s calling. A state machine that calls Glue, Lambda, and Redshift needs explicit permissions for all three, even if each of those services’ own execution roles are correctly configured.


Cross-Account Access: The Pattern Data Platforms Actually Need

Most organizations run separate AWS accounts for dev, staging, and production — a security best practice that immediately introduces cross-account IAM complexity. Understanding this pattern correctly prevents an entire category of “works in dev, fails in prod” bugs.

Scenario: A Glue job in the Data Platform account (111111111111)
needs to read from an S3 bucket in the Source System
account (222222222222)

Step 1: In the SOURCE account, create a bucket policy that trusts
the Data Platform account's role

Bucket policy on 222222222222's S3 bucket:
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:role/glue-etl-role"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::source-bucket/*"
}

Step 2: In the DATA PLATFORM account, the Glue role's identity-based
policy must ALSO allow this action

Identity policy on 111111111111's glue-etl-role:
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::source-bucket/*"
}

Both are required. Missing either one produces AccessDenied.

Why this trips up teams: in same-account scenarios, only the identity-based policy is strictly required (resource-based policies are optional reinforcement). In cross-account scenarios, both are mandatory. Engineers who’ve only worked in single-account setups configure only the identity-based side and can’t understand why cross-account access fails.

The alternative pattern — role assumption: instead of resource-based policies, some organizations use sts:AssumeRolewhere the Data Platform account's role assumes a role in the Source account that has direct access. This centralizes trust relationships but adds a layer of indirection that needs its own diagnostic understanding.


Diagnosing AccessDenied Errors Systematically

This is the diagnostic workflow that replaces guessing with a structured process.

AccessDenied error received
│
▼
Step 1: Read the FULL error message
AWS often includes the specific action and resource denied
Example: "User: arn:aws:sts::111:assumed-role/glue-role/session
is not authorized to perform: s3:GetObject on resource:
arn:aws:s3:::bucket/path because no identity-based
policy allows the s3:GetObject action"

This tells you: WHO (the role), WHAT action, WHAT resource,
and often WHY (no identity-based policy allows it)

│
▼
Step 2: Is this same-account or cross-account?
Same account → check identity-based policy on the role
Cross account → check BOTH identity-based policy AND
resource-based policy on the target

│
▼
Step 3: Check for explicit denies first
Explicit deny anywhere overrides any allow
Check: role's own policies, resource policy,
permission boundaries, Service Control Policies
(if the account is in an AWS Organization)

│
▼
Step 4: Check if the role has EVER had this permission
Use IAM Access Analyzer or CloudTrail to see if this
is a NEW failure (something changed) or has never worked

│
▼
Step 5: If CloudTrail shows the permission worked before,
search CloudTrail for policy change events
EventName: PutRolePolicy, AttachRolePolicy, PutBucketPolicy,
PutRolePermissionsBoundary
This identifies WHO changed WHAT and WHEN

The tool most data engineers don’t know exists: IAM Access Analyzer’s policy simulator lets you test “would this role be allowed to perform this action on this resource” without actually running the pipeline. This turns a production debugging session into a 30-second simulation.


Least Privilege Without Breaking Everything

“Least privilege” is easy to state and hard to implement correctly. The failure mode isn’t usually too much access — it’s engineers overcorrecting into permissions so narrow the pipeline breaks in ways that are hard to predict in advance.

The overcorrection pattern:
Too broad (common):
"s3:*" on "arn:aws:s3:::my-data-lake/*"
Works for everything, including things it shouldn't
Too narrow (overcorrection):
"s3:GetObject" only, missing "s3:ListBucket"
Job can read individual files if it knows the exact key,
but fails when Spark tries to list the prefix to discover files
Correct:
"s3:GetObject" + "s3:ListBucket" on specific prefixes,
"s3:PutObject" only on prefixes the job actually writes to,
scoped separately for read paths vs write paths

The specific permission gaps that cause confusing failures:

s3:ListBucket is a bucket-level permission, not an object-level permission — its Resource ARN is the bucket itself (arn:aws:s3:::bucket), not the object path (arn:aws:s3:::bucket/*). Engineers frequently apply it with the wrong resource pattern and it silently doesn't work, while s3:GetObject on the same policy statement (which does use the /* pattern) works fine — producing a job that can read known files but fails when it needs to discover files in a prefix.

glue:GetPartitions vs glue:GetTable — a job that only needs table metadata doesn't need partition-level permissions, but a job with dynamic partition filtering will fail without it, and the error message doesn't clearly indicate which specific Glue Catalog permission is missing.


Architecture Flow: IAM Across a Complete Pipeline

S3 Event (file arrives)
│
▼
EventBridge Rule
(needs: no IAM role itself, but the S3 bucket needs
resource policy allowing EventBridge to receive notifications)
│
▼
Step Functions State Machine
(needs: role trusting states.amazonaws.com,
permissions to invoke Glue, Lambda, etc.)
│
▼
Glue Job
(needs: role trusting glue.amazonaws.com,
S3 read on raw/, S3 write on processed/,
Glue Catalog read/write, CloudWatch Logs write)
│
▼
Redshift COPY
(needs: role trusting redshift.amazonaws.com,
ATTACHED to the cluster,
S3 read on processed/)
│
▼
Athena Query (via analyst)
(needs: user/role with Athena permissions,
S3 read on processed/,
Glue Catalog read,
S3 write on Athena query results bucket)
Every arrow in this diagram represents a trust boundary.
Every trust boundary needs its own explicit permission grant.
None of these are inherited from the step before it.

Failure Modes You’ll See in Production

The permission boundary silently narrowed by a security initiative. The opening scenario. A compliance or security team modifies organization-wide permission boundaries without coordinating with data teams whose pipelines depend on roles affected by the change. The pipeline that worked yesterday fails today with no code or configuration change on the data team’s side.

Cross-account access configured on only one side. A data platform team configures the identity-based policy allowing cross-account S3 access but the source account’s team never adds the corresponding bucket policy. The pipeline fails immediately, every time, with no ambiguity — but the fix requires coordinating with a team that doesn’t know they’re blocking anything.

IAM role not attached to Redshift cluster. A role is created with correct S3 read permissions and a correct trust policy, but was never attached to the Redshift cluster via the cluster’s IAM Roles configuration. Every COPY command fails with a generic access denied error that gives no indication the role simply isn’t associated with the cluster.

Overly broad permissions masking a real bug. A Glue job with s3:* on the entire data lake has a bug that writes output to the wrong prefix — overwriting Silver data with malformed output. Because the IAM policy is broad enough to allow this write, there's no permission error to signal the mistake. Scoped permissions would have caused the bug to fail loudly with AccessDenied instead of silently corrupting data.

Trust policy allows the wrong principal. An engineer copies a working Glue role’s trust policy to create a new role for a Lambda function, forgetting to change "Service": "glue.amazonaws.com" to "Service": "lambda.amazonaws.com". Lambda cannot assume the role at all — the function fails to even start, with an error about assume-role failure rather than a permissions error on a specific action.

Service Control Policies at the organization level blocking regional resources. An organization-wide SCP restricts resource creation to specific AWS regions for compliance reasons. A data engineer configures a pipeline in an unapproved region during testing. Every AWS API call fails with AccessDenied, and because the deny is happening at the SCP level (outside the account entirely), reviewing the role’s own policies shows nothing wrong.


Trade-offs: What IAM Optimizes For

IAM optimizes for:

  • Fine-grained, auditable access control across every AWS service
  • Temporary credential assumption (roles) over long-lived credentials (access keys)
  • Explicit deny as an unbreakable security boundary
  • Cross-account trust relationships that don’t require sharing credentials

IAM doesn’t optimize for:

  • Debuggability — error messages tell you what was denied, rarely why the underlying policy is configured that way
  • Change visibility — policy changes made by security/platform teams don’t automatically notify affected data teams
  • Simplicity at scale — a data platform with 20 pipelines across 3 accounts accumulates dozens of roles and policies that are hard to reason about holistically
  • Fast iteration — testing permission changes requires actually attempting the action; there’s no “dry run” for most operations outside the policy simulator

The honest trade-off: IAM gives you precise, auditable control over every action every identity can take. The cost is that this precision requires deliberate configuration at every trust boundary in your architecture, and failures in that configuration produce errors that require systematic diagnosis rather than obvious debugging.


Real-World Constraints

IAM policy size limits. Identity-based policies have a 6,144 character limit (2,048 for managed policies in some contexts). Pipelines with many specific resource ARNs can hit this limit, forcing either policy consolidation with wildcards (reducing precision) or splitting permissions across multiple attached policies (a role can have up to 10 managed policies attached).

IAM eventual consistency for policy changes. Unlike S3 (strongly consistent since 2020), IAM policy changes can take up to a few minutes to propagate globally. A policy change tested immediately after applying it may appear to still be denied — not because the change failed, but because it hasn’t propagated yet. This causes confusing “it started working on its own” debugging experiences.

Permission boundaries and Service Control Policies operate above individual role policies. A role’s own policy can grant a permission, but if a permission boundary or an SCP at the AWS Organization level doesn’t also allow it, the request is still denied. Data engineers who only have visibility into their own account’s IAM console may not be able to see Organization-level SCPs at all, requiring escalation to a platform or security team just to diagnose the failure.


What This Means for the Rest of the Series

Every service covered from Blog 5 onward assumes correctly configured IAM:

Blog 5 (Glue): every job needs the execution role pattern
covered in this article
Blog 6 (Redshift): the COPY command role must be attached
to the cluster, not just created in IAM
Blog 11 (Step Functions): orchestration requires explicit
permission to invoke every downstream
service, with no inheritance
Blog 17 (Lake Formation): governance-layer permissions work
alongside, not instead of, the IAM
patterns in this article

When a pipeline in a later blog fails with an access error, this article is the diagnostic reference.


Summary: The Engineering Lesson

IAM is not a checkbox you configure once during initial setup. It’s a distributed permission system where every trust boundary — service to service, account to account, role to resource — requires an explicit grant, and where the failure signature (AccessDenied) rarely explains which of the several possible causes actually applies.

The eight-month-old Glue job from the opening scenario didn’t fail because of bad IAM configuration. It failed because IAM configuration lives partially outside the data team’s visibility and control — modified by security initiatives, compliance requirements, and organizational policies that don’t automatically communicate their impact to the pipelines that depend on them.

The engineers who debug IAM quickly aren’t the ones who memorized every permission. They’re the ones who understand the evaluation model well enough to know where to look — role policy, resource policy, trust policy, permission boundary, SCP — in the right order.

That systematic diagnosis is what turns a two-hour guessing session into a five-minute fix.


🔥 Next in Series

Blog 4 - VPC, Networking, and Why Your Pipeline Can’t Connect to Anything

IAM controls who is allowed to make a request. Networking controls whether the request can physically reach its destination at all. The two failure modes look nearly identical from the outside — a connection that doesn’t work — but the diagnostic path and the fix are completely different.

We’ll go deep on subnets, security groups, VPC endpoints for S3 and Glue, and the specific networking configuration that determines whether your Glue job or EMR cluster can actually reach the resources it needs.


💬 Comment Below

What’s the most confusing IAM failure you’ve debugged in production?

Was it a permission boundary changed by a team you didn’t even know existed? A cross-account bucket policy that was configured on only one side for weeks before anyone noticed? A role that was never attached to a Redshift cluster, producing access denied errors that gave no hint the role itself was perfectly correct?

And — how long did it take before you found the actual cause?


Tags: aws-data-engineering, iam, aws-security, access-control, cross-account-access, aws-glue, redshift, least-privilege, dataforge