Skip to Content

MFA Delete and access logs

MFA Delete for protecting object versions, and S3 server access logs, including the logging-loop warning.

MFA Delete

MFA Delete forces users to enter a code from an MFA device (an authenticator app or a hardware key) before doing important, destructive operations on S3.

MFA is required to:

  • permanently delete an object version;
  • suspend versioning on the bucket.

MFA is not required to:

  • enable versioning;
  • list deleted versions.

Rules:

  • Versioning must be enabled on the bucket.
  • Only the bucket owner (the root user) can enable or disable MFA Delete.
  • It's turned on with the AWS CLI (or API), using the root user's credentials and MFA device, not from the console:
aws s3api put-bucket-versioning --bucket my-bucket \
  --versioning-configuration Status=Enabled,MFADelete=Enabled \
  --mfa "arn:aws:iam::123456789012:mfa/root-account-mfa-device 123456"

Because it needs root credentials (and root access keys are a bad idea), it's rarely used in practice; Object Lock is often a better fit. It's still a favourite on the exam.

S3 server access logs

Server access logging: every request to the app bucket, allowed or denied, from any account, is recorded as a log record in a separate log bucket in the same Region and account; logging a bucket into itself causes an endless loop Server access logging: every request to the app bucket, allowed or denied, from any account, is recorded as a log record in a separate log bucket in the same Region and account; logging a bucket into itself causes an endless loop

Every request is written to another bucket.

Audits may need a record of every access to a bucket. Server access logging does that.

  • Any request made to S3, from any account, allowed or denied, is logged into another S3 bucket.
  • The logs can be analysed with data analysis tools, such as Athena.
  • The log bucket must be in the same Region (and, per the AWS documentation, the same account) as the source bucket.
  • Logs are delivered on a best-effort basis, usually within a few hours.
  • The log format is documented on the server access log format page.

For API-level auditing with guaranteed delivery, use AWS CloudTrail (data events); server access logs add request details such as the HTTP status and bytes sent.

Warning: the logging loop

Never set the logging bucket to be the bucket being monitored. Every log record written into the bucket is itself a request, which creates another log record, and so on: a logging loop. The bucket grows exponentially, and so does the bill.

Real-world examples

  • A legal team must prove that no one has permanently deleted records. MFA Delete on the versioned bucket means a deletion needs the root user's MFA device.
  • A security team turns on server access logging for a sensitive bucket and queries the logs with Athena to find every 403 error from unknown IP addresses.

Exam tips

  • "Require MFA to permanently delete object versions" → MFA Delete (versioning required, root user, CLI).
  • "Who can enable MFA Delete?" → only the bucket owner's root user.
  • "Audit all requests to a bucket, including denied ones" → S3 server access logging to another bucket.
  • "Log bucket grows uncontrollably" → it's logging into itself.

Common traps

  • "An IAM admin can enable MFA Delete." Only the root user can.
  • "MFA Delete is needed to enable versioning." Only to suspend versioning or permanently delete versions.
  • "Send access logs to the same bucket to keep things simple." That creates a logging loop.
  • "Log bucket in another Region." It must be in the same Region.

Hands-on lab: turn on server access logging

Goal: log requests to your lab bucket into a separate log bucket.

Costs money

Log files for a few requests cost less than a cent. Any Region works. (MFA Delete isn't part of this lab: it needs root access keys, which you shouldn't create.)

Create the log bucket

Create a bucket saa-logs-<random> in the same Region as your lab bucket, with tag Project=saa-lab.

Turn on logging

On your lab bucket, Properties → Server access logging → Edit → Enable. Destination s3://saa-logs-<random>/lab/. Save; S3 updates the log bucket's policy so the logging service can write to it.

Make requests and wait

List and download a few objects in the lab bucket, and try to open one through its public URL (denied). After an hour or more, saa-logs-<random>/lab/ contains log files. Open one: each line is a request, with the operation, key, HTTP status and requester.

Expected result: a separate bucket collecting a log line for every request to your lab bucket, allowed or denied.

Clean up: turn off server access logging on the lab bucket, then empty and delete saa-logs-<random>.

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt