Nov 23, 20267 min read

Give Another AWS Account Access to an S3 Bucket

How cross-account S3 access works: the bucket policy in the owning account and the IAM policy in the other one, object ownership with ACLs disabled, KMS key policies for SSE-KMS buckets, the assume-role alternative, how to test it, and reading a bucket from another account in an Encore service.

Illustration for Give Another AWS Account Access to an S3 Bucket

Sharing a bucket with another AWS account comes up as soon as a company has a second account, such as a data account that receives exports from production. Inside one account an IAM policy on the role is enough, and across accounts the first attempt usually ends in AccessDenied.

This guide covers both policies, object ownership, KMS and how to test.

Why does Cross-Account access need two policies?

Within one account, a request is allowed if the caller's identity policy or the bucket policy allows it. Across accounts, the policy evaluation rules require both sides to agree: the bucket owner's resource policy must allow the other account's principal, and that principal's own account must allow the call in an identity policy. Each account controls its half, so the bucket owner decides who may read, and the other account decides which of its roles may use that access.

The examples below use account 111111111111, which owns the bucket acme-exports, and account 222222222222, whose reporting role reads from it.

How do you write the bucket policy?

The bucket policy in account 111111111111 names the role in the other account. s3:ListBucket applies to the bucket ARN and s3:GetObject to the object ARNs, and mixing the two is the most common reason a correct-looking policy still fails:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ReportingList", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::222222222222:role/reporting" }, "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::acme-exports", "Condition": { "StringLike": { "s3:prefix": "daily/*" } } }, { "Sid": "ReportingRead", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::222222222222:role/reporting" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::acme-exports/daily/*" } ] }

Naming a specific role is tighter than arn:aws:iam::222222222222:root, which delegates the decision to every identity in that account with a matching IAM policy. For access across a whole AWS Organization, a Condition on aws:PrincipalOrgID with the organization ID avoids listing accounts one by one. The cross-account walkthrough in the S3 docs follows the same shape.

What does the other account need?

The reporting role in account 222222222222 gets an identity policy for the same actions on the other account's bucket:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::acme-exports", "Condition": { "StringLike": { "s3:prefix": "daily/*" } } }, { "Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::acme-exports/daily/*" } ] }

Bucket names are global, so the ARN does not include the owning account, and nothing in this policy says which account the bucket belongs to. Code in the other account calls S3 with the bucket name as usual, with no special client setup, as long as it runs with the reporting role.

Who owns objects uploaded from the other account?

For write access, the old problem was that an object uploaded by account B was owned by account B, so the bucket owner could not read its own bucket's contents without a bucket-owner-full-control ACL on every upload. New buckets created after April 2023 default to the BucketOwnerEnforced setting for Object Ownership, which disables ACLs and makes the bucket owner the owner of every object. Check older buckets with aws s3api get-bucket-ownership-controls --bucket acme-exports and switch them once nothing depends on ACLs.

What changes for SSE-KMS encrypted buckets?

Objects encrypted with a KMS key need a third permission: the key policy has to let the other account use the key. A bucket that uses the AWS managed aws/s3 key cannot be shared across accounts for those objects, since that key policy cannot be edited, so cross-account buckets need a customer managed key. Its key policy gets a statement for the other account, and the other account's role gets kms:Decrypt (and kms:GenerateDataKey for uploads) on that key ARN, as the KMS cross-account docs describe:

{ "Sid": "AllowReportingDecrypt", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::222222222222:role/reporting" }, "Action": ["kms:Decrypt", "kms:DescribeKey"], "Resource": "*" }

A GetObject that fails only on encrypted objects, while listing works, is almost always this missing key permission.

When is an assumed role better?

The alternative is a role in the bucket's account, say exports-reader in 111111111111, with a trust policy that lets account 222222222222 assume it. Callers in account B call sts:AssumeRole and use the temporary credentials, so all S3 and KMS permissions sit in one account and no bucket policy is needed. That is cleaner when access spans several buckets, queues and keys, and it costs an extra STS call plus credentials that expire after an hour by default. A bucket policy keeps the caller's own identity in CloudTrail and needs no credential switching, which fits one shared bucket.

How do you test Cross-Account access?

Run the checks as the role in the other account, with a CLI profile that assumes it:

~
$ aws sts get-caller-identity --profile reporting$ aws s3 ls s3://acme-exports/daily/ --profile reporting$ aws s3 cp s3://acme-exports/daily/2026-11-22.csv.gz . --profile reporting

The first command proves which principal you are, which rules out the surprisingly common case of testing with the wrong profile. If listing fails, check the ListBucket statements on both sides, and if listing works but the copy fails, check the object ARN pattern and then KMS. The S3 access denied guide covers the error messages in more detail.

How do you read a bucket from another account in an Encore service?

Encore

Encore brings infrastructure from code, so a service declares the bucket it uses and Encore provisions it in your AWS account with an IAM role for the service. When the bucket already exists, the import docs let you point that declaration at it instead: the import dialog asks for the AWS account that owns the bucket from your connected accounts, its region and its name, and the prerequisite is that the Encore IAM role has permission to access the bucket, which is the same bucket policy work covered above.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.

Set up the app

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

~
$ encore app create reporting --example=ts/hello-world$ cd reporting && mkdir exports

A reporting service that lists the daily export files and returns a short-lived download link for one of them:

// exports/encore.service.ts import { Service } from "encore.dev/service"; export default new Service("exports");

The export endpoint writes to the bucket:

// exports/exports.ts import { api, APIError } from "encore.dev/api"; import { Bucket } from "encore.dev/storage/objects"; // Imported in the Encore dashboard to point at the existing acme-exports bucket. const exportsBucket = new Bucket("daily-exports"); const DATE = /^\d{4}-\d{2}-\d{2}$/; // Exports hold another account's data, so only signed-in staff with access to them may list or download. export const list = api( { expose: true, auth: true, method: "GET", path: "/exports" }, async (): Promise<{ files: { name: string; size: number }[] }> => { const files: { name: string; size: number }[] = []; for await (const entry of exportsBucket.list({ prefix: "daily/", limit: 100 })) { files.push({ name: entry.name, size: entry.size }); } return { files }; }, ); export const link = api( { expose: true, auth: true, method: "GET", path: "/exports/:date" }, async ({ date }: { date: string }): Promise<{ url: string }> => { if (!DATE.test(date)) throw APIError.invalidArgument("date must be YYYY-MM-DD"); const key = `daily/${date}.csv.gz`; if (!(await exportsBucket.exists(key))) throw APIError.notFound("no export for that date"); const { url } = await exportsBucket.signedDownloadUrl(key, { ttl: 600 }); return { url }; }, );

encore run stores bucket objects on the local filesystem, so the endpoints can be tried with test files before anything touches the shared bucket, and the same code reads the shared bucket once the declaration is imported. The object storage docs list the bucket methods used here, and the bucket name in code stays the same across local, preview and production environments.

An agent extending this service, for example to parse each export into Postgres, writes the parsing code against the bucket declaration and tests it locally, and the cross-account policy stays in AWS where it cannot change it.

Best fit: Teams that receive data in a bucket owned by another account and want a service to read it with the bucket declared in code and the access policy kept in AWS.

Cross-Account S3 checklist

  • Allow the other account's role in the bucket policy, with ListBucket on the bucket ARN and object actions on bucket/*.
  • Attach a matching identity policy to that role in its own account.
  • Use BucketOwnerEnforced object ownership so the bucket owner owns every upload.
  • Use a customer managed KMS key and grant the other account in its key policy.
  • Prefer an assumed role when access spans several resources.
  • Test as the other account's role, starting with aws sts get-caller-identity.

Frequently asked questions

How do I give another AWS account access to my S3 bucket?

Add a bucket policy in your account that allows the other account's role, for example arn:aws:iam::222222222222:role/reporting, to call s3:ListBucket on the bucket and s3:GetObject on its objects. Then the other account attaches an IAM policy to that role allowing the same actions on your bucket, since cross-account access needs both.

Why do I get Access Denied on a cross-account S3 bucket when the bucket policy allows it?

The usual causes are a missing IAM policy on the caller's role in its own account, a ListBucket grant on bucket/* instead of the bucket ARN, or an SSE-KMS key whose key policy does not allow the other account. Objects encrypted with the AWS managed aws/s3 key cannot be read from another account at all.

Who owns objects that another account uploads to my bucket?

With the default BucketOwnerEnforced setting for Object Ownership, the bucket owner owns every object and ACLs are disabled, so uploads from another account need no bucket-owner-full-control ACL. Older buckets with ACLs enabled may still leave the uploader as the object owner.

When should I use a bucket policy instead of an assumed role for cross-account S3 access?

Use a bucket policy when the other account only needs this bucket and its callers keep their own identity in logs. Use a role in the bucket's account that the other account assumes when access spans several resources or you want all permissions defined in one place.

Can Encore declare a bucket that another AWS account writes to?

Yes. You declare the bucket in the service, Encore provisions it in your own AWS account with an IAM role for the service, and the cross-account access policy stays in AWS. The service then reads the objects with the bucket API in application code.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders