How to edit a file in S3 without downloading it first

TL;DR

S3 has no edit API, only GetObject and PutObject — every 'edit' is really a full read, a change, and a full conditional rewrite of the object. For small text files (JSON, YAML, Markdown, config, .env, logs, and similar, up to 1 MB in S3 Viewer) that loop is fast enough to feel instant. S3 Viewer's Edit button opens a text-like object directly in the browser and saves it back with the same reviewed-ETag condition every replacement uses, so a change made elsewhere in the meantime is caught instead of silently overwritten.

Steps

Step-by-step.

  1. 01

    In S3 Viewer: click Edit on a text-like object

    Open an object with a text-like content type or extension (.json, .yml, .md, .csv, .env, .log, and similar) under 1 MB and click Edit. The preview switches to a plain-text editor with line numbers; a dirty indicator marks unsaved changes, and Cmd/Ctrl+S saves without reaching for the mouse. Leaving with unsaved changes prompts for confirmation.
  2. 02

    Save conditions on the version you opened

    Saving PUTs the new content back with the ETag you had open as a condition — the same conditional replacement path a manual re-upload uses. If the object changed after you opened it, the save is refused with a message to reload rather than overwriting someone else's write.
  3. 03

    AWS CLI: download, edit, upload

    No shortcut here — copy the object down, edit it locally, and copy it back. Check the ETag before and after if you want the same protection S3 Viewer gives you automatically.
    aws s3 cp s3://my-bucket/config/settings.json ./settings.json
    $EDITOR ./settings.json
    aws s3 cp ./settings.json s3://my-bucket/config/settings.json
  4. 04

    AWS SDK: getObject, transform, conditional putObject

    Read the body, make your change, and write it back with IfMatch set to the ETag you read — this is the scripted version of what S3 Viewer's Edit does under the hood.
    const { Body, ETag } = await s3.getObject({ Bucket: 'my-bucket', Key: 'config/settings.json' });
    const text = await Body.transformToString();
    const updated = JSON.stringify({ ...JSON.parse(text), debug: false });
    
    await s3.putObject({
      Bucket: 'my-bucket',
      Key: 'config/settings.json',
      Body: updated,
      IfMatch: ETag,
    });
  5. 05

    Large or binary files: edit locally instead

    An in-browser editor only makes sense for small text — S3 Viewer caps it at 1 MB, and a multi-megabyte log or a binary file wouldn't render usefully as a textarea anyway. Download, edit with the right tool, and re-upload for anything past that line.
Under the hood

What's actually happening.

S3's object API has exactly two operations that touch content: GetObject reads the whole body, and PutObject replaces it whole. There is nothing between them — no patch, no append, no byte-range write. Editing a file is therefore always: read everything, change what you want, write everything back.


S3 Viewer's Edit button runs that loop for you: it HEADs the object first (refusing anything over 1 MB before a byte transfers), streams the body into a plain-text editor with the object's ETag captured alongside it, and on save PUTs the new content back through the same route a manual replacement upload uses — expectedETag included, so a change made elsewhere between opening and saving is caught as a conflict rather than silently discarded.


The 1 MB ceiling isn't arbitrary caution: a textarea holding a multi-megabyte file is a poor editor regardless of how fast the network is, and the file is more likely binary or log-shaped at that size anyway. Nothing about the underlying read-and-write pattern actually changes past that point — only the UI stops being the right tool for it.

FAQ

Common questions.

Can I edit a file directly in S3?

Not literally — S3 has no in-place edit call. What every tool that offers 'editing' actually does is read the full object, apply the change, and write the full object back with PutObject. For small text files this round trip is fast enough that it feels like an edit. S3 Viewer's Edit button does exactly this for text-like files up to 1 MB, directly in the browser.

What file types can S3 Viewer edit in place?

Text-like content types and extensions: JSON, TXT, MD, CSV, YAML/YML, XML, HTML, CSS, JS, TS, SH, ENV, TOML, INI, LOG and SVG, up to 1 MB. Anything larger, or a binary format, opens for preview only — download, edit locally, and re-upload instead.

Will I lose my changes if someone else edits the file first?

No — the save carries the ETag of the version you opened as a condition, so if the object changed in the meantime the save is refused with a message to reload, rather than silently overwriting the other change. This is the same protection S3 Viewer's upload replacement flow uses everywhere else.

How do I edit a JSON or config file in an S3 bucket from the terminal?

aws s3 cp it down, edit with your usual editor, then aws s3 cp it back up to the same key. Pass --if-match with the object's ETag on the way back if you're scripting this and want to guard against a concurrent change, since the AWS CLI doesn't do that for you automatically.

Does editing a file in S3 create a new version?

Only if the bucket has versioning enabled — then the PutObject that saves your change creates a new version and the previous content remains recoverable. Without versioning, the save overwrites the object outright and the prior content is gone once it succeeds.

Can I edit a file in Cloudflare R2 or Backblaze B2 the same way?

Yes. Saving an edit is a conditional PutObject, which S3 Viewer already runs on every connected provider for replacements — R2 and B2 included, using a HEAD-and-compare check on the providers that don't enforce the condition themselves rather than trusting a header they might ignore.
Use S3 Viewer for this

Skip the CLI. Try it in the browser.

S3 Viewer turns the steps above into a single click. Open source, self-hostable, free.