dev.baschen.is

Private cross-account S3 with access points and a gateway endpoint

A common landing-zone request: workloads in a provider account need a bucket that lives in a data account, and none of it may touch the internet. The tempting answer routes S3 through the Transit Gateway. The better one never sends S3 traffic there at all.

The request path

  1. The task role addresses the access point ARN, not the bucket name, and may only Get, Put and List through it.
  2. The call leaves through an S3 gateway endpoint in the spoke VPC. Its endpoint policy allows only the data account's access points and the ECR layer bucket.
  3. The access point in the data account is locked to the spoke VPC, and its policy admits only the task role.
  4. The bucket policy delegates to access points. The bucket is versioned, TLS-only, with Block Public Access on.
  5. The KMS key allows cross-account use only via S3, with rotation enabled.

Four policies are evaluated in order: endpoint, access point, bucket, key. Each one narrows the request, so a mistake in one is caught by another.

The details that bite

Bonus: an internal API entrypoint at /api/{service}

The same repository adds one internal entrypoint for every API served from ECS or EKS, where each service registers itself. It is deliberately an internal ALB rather than API Gateway: private REST APIs centralize routing (every new route redeploys the whole API) and still need a VPC Link and an NLB to reach containers, and HTTP APIs cannot be private at all. An internal ALB is reachable across the TGW, talks to ECS tasks and EKS pods through ip target groups, and its listener rules are exactly the per-service declaration wanted.

A service's own Terraform calls modules/api-service, which adds a target group and a rule for /api/<name>/*. Rule priority is left to AWS: paths are disjoint, so order never matters and nobody has to coordinate. The path is forwarded unchanged, so services serve under their prefix, health check included.

On top of that sit a base-infra module (an ECS cluster with enhanced Container Insights, Fargate and Fargate Spot, and an ECR creation template enforcing immutable semver tags) and a microservice module that creates a service's repository, task definition, roles, logs, ECS service with circuit breaker, and its entrypoint rule in one call. Immutable tags mean a version can never be re-pushed; rollback is redeploying the previous one.

← All articles