Authentication is the act of proving WHO is calling. On AWS, every data-plane and control-plane request is signed with either long-lived credentials (an IAM user access key, rarely appropriate for pipelines) or short-lived credentials issued by AWS Security Token Service (STS) when a role is assumed. The data engineer almost always picks the second path: AWS Lambda functions, AWS Glue jobs, Amazon EMR clusters, Amazon Redshift clusters, Amazon MWAA environments, and Amazon EC2 instances all assume an IAM service role at runtime and receive rotating temporary credentials through the instance metadata service or the AWS SDK credential provider chain. Long-lived access keys remain only for human break-glass accounts and for narrow integration cases like CI runners that cannot use OIDC federation.
The chapter you are reading sits downstream of pipeline orchestration, so the authentication surface to focus on is service-to-service. A typical batch job sequence runs: Amazon EventBridge invokes AWS Step Functions; Step Functions calls AWS Glue StartJobRun; the Glue job assumes its own service role to read from Amazon S3, write to Amazon Redshift through a Glue connection, and emit metrics to Amazon CloudWatch. Five role assumptions, all signed with SigV4, all auditable by AWS CloudTrail. If any link in that chain hard-codes an access key in an environment variable, the chain has a credential leak waiting to be exfiltrated.
Authorization rides on the same trust boundary but answers a different question: WHAT can the authenticated principal do. AWS evaluates authorization through a layered policy engine: service control policies (SCPs) at the AWS Organizations level, resource control policies (RCPs) at the same scope, permissions boundaries on the identity, identity-based policies attached to the role or user, resource-based policies attached to the resource (S3 bucket policy, KMS key policy, Lambda function policy), session policies passed in AssumeRole, and AWS Lake Formation grants for catalog objects. An action is allowed only if NO policy contains an explicit Deny and at least one Allow exists in the relevant scope. New engineers regularly forget that an explicit Deny anywhere in the chain wins; pipelines that "should" work but return AccessDenied are almost always tripped by an SCP or a resource policy with a tight aws:SourceVpce or aws:PrincipalOrgID condition.
# A Glue job assumes its service role automatically; the boto3 client
# inherits the role's temporary credentials. No keys, no rotation code,
# no Secrets Manager call. This is the recommended pattern.
import boto3
from awsglue.context import GlueContext
from pyspark.context import SparkContext
glue_ctx = GlueContext(SparkContext.getOrCreate())
s3 = boto3.client("s3") # signed with the job's role creds
resp = s3.get_object(Bucket="dea-lake-raw-dev", Key="orders/2099-q1.parquet")
# Verify which identity an EC2-hosted process is actually using before
# debugging an AccessDenied. The output reveals the assumed-role ARN
# and the session name, which links directly to a CloudTrail event.
aws sts get-caller-identity \
--query "{Account:Account,Arn:Arn,UserId:UserId}" \
--output table
Applying Authorization Mechanisms
The four authorization styles a data engineer touches daily are: identity-based IAM policies on the principal (a Glue role can read this bucket), resource-based policies on the resource (this bucket allows reads from a specific role), Lake Formation grants on cataloged objects (this principal has SELECT on this column), and database-engine grants inside Amazon Redshift or Amazon RDS (this Redshift user has SELECT on schema analytics). For S3 data lakes, identity-based + Lake Formation is the recommended path; raw S3 bucket policies are reserved for cross-account boundaries and VPC-endpoint pinning. For Amazon Redshift, identity grants get the principal to the cluster, then Redshift engine grants control table-level access. Mixing the two layers takes practice: it is easy to grant a role redshift:GetClusterCredentials and assume the work is done, only to find the database itself has no GRANT SELECT to the resulting user.
Data Masking and Anonymization for Compliance
Masking transforms sensitive data so the consumer cannot recover the original value. Anonymization goes further and removes the link to the natural person entirely. AWS offers three production-grade hooks for the data engineer. Amazon Redshift dynamic data masking attaches a policy to a column that rewrites the value at query time based on the user's role, leaving the stored data untouched. AWS Lake Formation data filters add cell-level filters and column-level masking to Glue Catalog tables, applied transparently when queries come through Amazon Athena, Amazon Redshift Spectrum, or AWS Glue ETL. For object-level use cases (PDFs, logs, CSV files served to a downstream tenant), Amazon S3 Object Lambda lets a Lambda function rewrite the bytes during a GetObject call, redacting PII before the caller ever sees it.
-- Amazon Redshift dynamic data masking: SSNs become last-4 for analysts,
-- full clear-text for the compliance role. The base table is unchanged.
CREATE MASKING POLICY mask_ssn_last4
WITH (ssn VARCHAR(11))
USING ('XXX-XX-' || SUBSTRING(ssn FROM 8 FOR 4));
ATTACH MASKING POLICY mask_ssn_last4
ON analytics.customer (ssn)
TO ROLE analyst_role
PRIORITY 10;
💡 Exam Trap: Amazon Redshift dynamic data masking is enforced ONLY for users connecting through the Redshift SQL engine. A Glue job that uses Redshift UNLOAD to write the table to S3 receives the UNMASKED values because the unloading principal is the cluster role, not the analyst role. To preserve masking through UNLOAD, attach the policy to the role that actually runs the UNLOAD, or unload through a view that hardcodes the mask.
Analyzing Logs with AWS Services
The audit story is incomplete without analysis tooling. Once CloudTrail emits to S3, CloudWatch Logs receives application output, and VPC flow logs land in their bucket, the data engineer queries them with three engines depending on volume and latency. Amazon CloudWatch Logs Insights runs a purpose-built query language over log groups for ad-hoc investigation: parse, filter, stats, sort, and limit. Amazon Athena queries log data already in S3 using standard SQL with partition projection on year/month/day/account/region. Amazon OpenSearch Service ingests near-real-time logs and gives Kibana-style dashboards with sub-second filters for security operations.
-- Athena over CloudTrail logs partitioned by projection. Find every
-- principal that called s3:DeleteBucket in the audit window.
SELECT useridentity.arn AS principal,
eventtime,
requestparameters
FROM cloudtrail_logs
WHERE region = 'us-east-1'
AND year = '2099' AND month = '02'
AND eventname = 'DeleteBucket'
ORDER BY eventtime DESC;
📊 Limit: CloudWatch Logs Insights queries scan multiple log groups in one execution and time out at 60 minutes; results return up to 10,000 rows. For broader retrospective audits, export the log group to S3 and query with Athena instead.
Data Access Through Amazon SageMaker Catalog Projects
The Amazon SageMaker Catalog (the business catalog inside SageMaker Unified Studio) layers a project abstraction on top of the AWS Glue Data Catalog and Lake Formation. A project is the unit of access: members of a project receive scoped permissions on the data products published to it, and access requests flow through a subscription workflow that records grantee, grantor, and approval rationale. The data engineer's job is to publish curated tables and Iceberg datasets to a project, attach the appropriate AWS Lake Formation tags or named-resource grants, and let project administrators approve cross-project subscriptions. This pattern replaces ad-hoc IAM role sprawl with a governed, audited request flow.
🎯 Scenario: A retail analytics team needs read-only access to the
customer_360Iceberg table owned by the marketing data engineering team. Without SageMaker Catalog projects, the analytics team would email the marketing engineer who would create a Lake Formation grant and document the rationale in a wiki. With projects, the analytics lead clicks Subscribe in the catalog, the marketing project owner approves, and Lake Formation creates the underlying GRANT automatically with the subscription ID recorded as the audit trail.
⚠️ Anti-Pattern: Embedding an IAM user's access key directly in an Amazon EMR step configuration so the cluster can call a partner API. The keys log into CloudTrail on every step run, persist in the EMR cluster configuration history, and survive cluster termination if logs are exported. Replace with a Secrets Manager lookup wrapped in a Lambda invocation, or with a partner-side AssumeRole if they support cross-account roles.
Decision Anchor. Choose IAM role authentication when the caller is an AWS service or workload that supports instance profiles or service roles (Lambda, Glue, EMR, EC2, ECS, MWAA). Choose AWS Secrets Manager retrieval of a long-lived token when the caller integrates with a non-AWS endpoint that has its own bearer-token auth. Never choose long-lived IAM access keys baked into code for a runtime that can assume a role; that is a recoverable credential exposure.
