# Connect AWS and create a setup

> The checklist, the access stack, the errors you can see and the fix for each, before and while you connect an AWS account.

Source: https://diakrin.com/docs/connect-aws

An owner, admin or Technical administrator connects one AWS account by creating a `DiakrinAccess-<id>` CloudFormation stack with an AWS administrator's help, then creates a setup on it; this page lists what the account must have first and what to do when a step stops.

## Before you start

| You supply | Example | Comes from |
| --- | --- | --- |
| The 12-digit AWS account ID | `123456789012` | AWS console, top right |
| An AWS person who can create CloudFormation stacks and named IAM roles and policies | An AWS administrator | AWS IAM. Diakrin does not check this beforehand |
| A home region for the access stack | `us-east-1` | You choose it on the Connect page. It only holds Diakrin's access stack |
| A choice on **Show actual AWS cost** | On or off | Connect page. Default on |
| A Diakrin role that can manage infrastructure | Owner, admin or Technical administrator | **Settings → Members** |
| A region for the setup | `eu-west-1` | One of the regions the New setup page offers (see [Region](#region)) |
| A monthly budget ceiling for the setup | `300` US dollars | An owner or admin saves it. A Technical administrator cannot |

## Checklist

Each row has its own section. **Not checked** means Diakrin does not read it; it can only show up as a failed step.

| # | Prerequisite | Needed for | Who checks it today |
| --- | --- | --- | --- |
| 1 | [Connection is verified (the access stack exists and matches)](#connection-verified) | Connect | AWS itself, then Diakrin's check of the stack |
| 2 | [Access version is current](#access-update) | Connect and setup | Diakrin, before anything is created |
| 3 | [No policy blocks Diakrin's roles](#organization-policies) | Connect and setup | Not checked |
| 4 | [Region](#region) | Setup | The console and the server |
| 5 | [Network](#network) | Setup | The console and the server |
| 6 | [Service quotas](#quotas) | Setup | Not checked |
| 7 | [Service-linked roles](#service-linked-roles) | Setup | Diakrin creates them |
| 8 | [Budget ceiling and price](#budget-ceiling-and-price) | Setup | Diakrin, before anything is created |
| 9 | [App address (nothing to provide)](#app-address) | Setup | Diakrin |

> [!NOTE]
> Planned, not shipped: a read-only scan that checks these prerequisites for you and stops setup creation when the account is not ready. Until it ships, the "Who checks it today" column is the whole truth. Each section below maps to one prerequisite so a later check can link to it.

## Connection is verified

What: **Cloud → Accounts → Connect AWS** opens CloudFormation in the home region with the stack name `DiakrinAccess-<id>` (the first 8 characters of the connection ID) and every value filled in. The template creates three IAM roles and eleven managed policies and nothing else. The person who opens it must be signed in to the same AWS account, tick **I acknowledge that AWS CloudFormation might create IAM resources**, and choose **Create stack**. There is one stack per connection, not one per account.

How to check that the signed-in AWS identity belongs to the right account:

```sh
aws sts get-caller-identity --query Account --output text
```

You should see the 12-digit ID you entered on the Connect page.

After you create the stack, the Connect page checks it by itself every 15 seconds while it is open, for up to 60 minutes; **Check now** checks at once. Diakrin also keeps checking for 60 minutes when the page is closed. The check reads the stack, the template bytes, each role's trust, each policy and the roles' identities; it never changes anything in your account.

If it fails: see the table at the end of this page.

## Access update

What: the current access version is 1.1.1. A setup needs 1.1.0 or later; versions before 1.1.0 are retired. Version 1.1.0 cannot create new CloudFormation stacks, so choose the update when the account shows **Update available**; Diakrin does not force it today.

How to check: open **Cloud → Accounts**. A connection with a newer version shows "Version 1.1.1 of the access stack is available. Your current version keeps working until you update."

If it is retired: creating a setup answers `ACCOUNT_ACCESS_UPGRADE_REQUIRED`: "Open Cloud → Accounts, install and verify the new AWS access stack, then retry this setup." Retired stacks are not updated in place; you install the new per-connection stack beside the old one. For a current stack, choose **Update in AWS**: it opens a CloudFormation update with the saved values, you review the change set in AWS, and Diakrin makes no change itself.

## Organization policies

What: Diakrin's roles and every role it creates must be allowed by your AWS Organizations service control policies (SCPs) and your IAM permissions boundaries. Diakrin does not read your SCPs. A policy that denies creating IAM roles or policies named `DiakrinAccess-*`, or any action in the access roles' permissions, shows up as a failed stack or as `ACCESS_DENIED` on a resource, with the denied AWS action named.

Two things Diakrin does check:

- The three access roles must have no permissions boundary. If an organization adds one, verification fails with `ACCOUNT_ACCESS_TRUST_MISMATCH`.
- The roles must be exactly as the template defines them. Anyone who edits a trust policy or attached policy gets `ACCOUNT_ACCESS_TRUST_MISMATCH` or `ACCOUNT_ACCESS_POLICY_MISMATCH`.

To compare your policies with what Diakrin needs, review the permissions Diakrin lists on the Connect page before you open AWS. It lists every role, every policy and what Diakrin can never do, and links the raw template.

If it fails: ask the owner of the SCP to allow the named action, or exempt the `DiakrinAccess-*` roles, then choose **Update in AWS** or try the setup again.

## Region

The access stack's home region is yours to choose; the Connect page offers 34 commercial `aws`-partition regions.

A setup region is narrower: the New setup page offers only the regions the loaded release prices. Every reviewed release in the repository prices the same 17 regions: `ap-northeast-1`, `ap-northeast-2`, `ap-northeast-3`, `ap-south-1`, `ap-southeast-1`, `ap-southeast-2`, `ca-central-1`, `eu-central-1`, `eu-north-1`, `eu-west-1`, `eu-west-2`, `eu-west-3`, `sa-east-1`, `us-east-1`, `us-east-2`, `us-west-1` and `us-west-2`. These are the regions AWS enables by default; an opt-in region such as `ap-east-1`, `me-south-1`, `af-south-1` or `eu-south-1` cannot host a setup today. Diakrin does not check whether a region is enabled in your account.

If you pick a region the release does not price, the answer is `REGION_NOT_SUPPORTED_IN_RELEASE`: "Diakrin's current release has no reviewed AWS prices for this region yet. Choose a region from the offered list." Reviewed prices expire after 30 days; an expired price blocks the app address with `GATEWAY_COST_REVIEW_REQUIRED`, so ask your Diakrin contact.

The region of a setup is fixed once its foundation exists. CloudFront certificates always live in `us-east-1`, whatever the setup region.

## Network

What: in **Review** you choose where the setup's network lives.

| Choice | What Diakrin does |
| --- | --- |
| **Existing VPC** (default) | Uses your VPC. It needs at least two **private** subnets in different Availability Zones. A subnet is private only if its route table has no internet gateway route and it does not assign public addresses. Diakrin creates no subnets, routes or endpoints; it adds this setup's own security groups, database, internal load balancer and image registry |
| **Create a new VPC for this setup** | Creates a private VPC with two private subnets and five endpoints. It creates no NAT gateway and no internet gateway of its own for the foundation |

Diakrin lists the VPCs in the account and region and preselects the only eligible one. The default VPC rarely qualifies because its subnets are public.

Outbound access: apps pull images and read secrets over HTTPS. Your private subnets need either a default route (NAT gateway or equivalent) or all five endpoints (`ecr.api`, `ecr.dkr`, `logs`, `secretsmanager` and S3). Diakrin warns when it finds neither and does not block creation.

Internet gateway: apps are published through CloudFront, which needs an internet gateway on the VPC. Diakrin looks for the one your route tables already use and passes it to the setup stack for you; nothing is entered by hand. If your VPC has a gateway attached that no route table uses, Diakrin cannot see it, tries to attach a second one, AWS refuses, and the stack rolls back. Fix: give one of the VPC's route tables a route through that gateway, then try again.

The network is fixed once the setup exists. Refusals you can see:

| Code | Text |
| --- | --- |
| `EXISTING_VPC_UNAVAILABLE` | The chosen VPC is not available in this AWS account and region. |
| `EXISTING_SUBNET_NOT_PRIVATE` | A chosen subnet routes to an internet gateway or assigns public addresses. Choose private subnets. |
| `INVALID_DATABASE_SUBNET_ZONES` | Choose two private subnets in different Availability Zones. |
| `NETWORK_IMMUTABLE` | A setup's network cannot change after its foundation exists. |

## Quotas

What: a setup creates an RDS PostgreSQL instance, an ECS cluster, an internal load balancer, a registry, a KMS key, a bucket and a log group. The app address adds a CloudFront distribution, a Lambda relay, an ECS service and a VPC endpoint. Diakrin does not read your quotas first. One quota failure is recognized after the fact: a brand-new account's Lambda concurrency quota is 10, which is too low for the gateway relay, so the gateway stack rolls back (`GATEWAY_LAMBDA_CONCURRENCY_QUOTA`) and the setup shows the gateway as not taking traffic. There is no dedicated message for it yet.

How to check, for the Lambda case: in the AWS console open **Service Quotas → AWS services → AWS Lambda → Concurrent executions** in the setup region. A value of 10 is the new-account default; request an increase before you create the setup.

## Service-linked roles

Diakrin creates the ECS, Elastic Load Balancing and RDS service-linked roles itself, immediately before it creates each setup foundation, and never deletes them. If a stack event still reports a missing role, run the command the setup shows, for example:

```sh
aws iam create-service-linked-role --aws-service-name ecs.amazonaws.com
```

You should see a role named `AWSServiceRoleForECS`. The other two services are `elasticloadbalancing.amazonaws.com` and `rds.amazonaws.com`. Then try the setup again. The CloudFront service-linked roles are created through the setup's Execution role.

## Budget ceiling and price

What: the ceiling is the most Diakrin will approve for the shared foundation's estimated monthly cost. It is not an AWS billing cap.

- A **current owner or admin** must save the ceiling; a Technical administrator cannot (`FOUNDATION_BUDGET_REVIEW_REQUIRED`).
- Only seven-day database backups are priced; a longer retention answers `COST_VERIFICATION_REQUIRED`.
- A known estimate above the ceiling blocks creation (`FOUNDATION_BUDGET_EXCEEDED`: "Approval cannot override this hard limit."). An unknown estimate does not block, and is never shown as zero.
- The quote must be less than 15 minutes old; Create re-reads it.

## App address

What: you provide no DNS and no certificate. Each setup gets its own address, `<app>.<label>.p.diakrin.dev`. Diakrin owns `p.diakrin.dev` and writes only one NS record there. In your account it creates a Route 53 public hosted zone for `<label>.p.diakrin.dev` (with a CAA record that allows only Amazon), an ACM wildcard certificate in `us-east-1`, and the CloudFront distribution. See [App addresses and company domains](/docs/domains).

Your own company domain on a setup is planned: the **Connect a domain** button answers "Available soon. This setup is updating automatically; nothing to do." today.

## Connect, step by step

1. Open **Cloud → Accounts** and choose **Connect AWS**.
2. Enter the 12-digit account ID, choose the home region, choose whether to show actual AWS cost, and review the permissions Diakrin lists.
3. Choose **Open AWS**. CloudFormation opens with the stack `DiakrinAccess-<id>` filled in.

> [!WARNING]
> Stop here until an AWS administrator signed in to the same account has read the stack's change set and ticked the IAM acknowledgement. Do not let a coding agent create the stack: the link carries the connection's external ID.

4. Choose **Create stack**. Leave every other field as it is. It takes 2 to 4 minutes.
5. Return to Diakrin. The account turns **Connected** by itself.
6. Open **Cloud → Setups → New setup**, choose the account, choose the region, a size (Starter or Resilient) and a ceiling, then follow [Set up your company cloud](/docs/company-cloud#create-the-setup-on-aws).

To remove Diakrin's access, delete the `DiakrinAccess-<id>` stack in CloudFormation. Removing the account in the console is "coming soon"; deleting the connection in Diakrin never touches your stack.

## What Diakrin asks for and why

Diakrin holds no long-lived AWS keys. It assumes roles in your account with an external ID.

| Role | Who may assume it | Used for |
| --- | --- | --- |
| Reader | Diakrin's reader role, with the external ID | Read-only inventory and metrics; read of the cost export bucket when you allow cost |
| Controller | Diakrin's control role, with the external ID | Starting reviewed change sets and builds, writing CNAME, A and AAAA DNS records, requesting tagged certificates. It cannot create resources itself |
| Execution | Only `cloudformation.amazonaws.com`, from your account | The identity CloudFormation uses to create and change Diakrin's resources. Diakrin cannot assume it |

What Diakrin never does:

- It never creates IAM users or access keys.
- It never changes the `DiakrinAccess-*` stack, roles or policies: an explicit deny blocks any write to them, so only you can edit your own access.
- It never changes resources that do not carry the `diakrin:managed` and `diakrin:connection` tags it set, except where AWS cannot tag-fence an action (CloudFront, ACM, task definitions and a few others, which are limited by name instead).
- It never reads secrets outside `diakrin/*`, or buckets outside `diakrin-*`.
- It never touches AWS Organizations or CloudTrail.
- Every role it creates is capped by a permissions boundary that also denies assuming roles outside your account.

With **Show actual AWS cost**, the Reader reads a cost export in a bucket named `cur-export-<account id>`, which needs a separate `DiakrinCostExport` stack in `us-east-1`. The console does not offer a link for that stack yet, so actual cost may show as unavailable until it does.

## If it fails

| Symptom | Cause | Fix |
| --- | --- | --- |
| "Diakrin can't find the stack yet" (`ACCOUNT_ACCESS_NOT_FOUND`) | Stack not created, created in another region or account, or deleting | Open AWS again from the Connect page and create it in the home region |
| After 3 minutes: "Did AWS show an error?" | The stack rolled back | Open the stack's Events in AWS; delete a rolled-back stack, then open AWS again |
| "AWS couldn't finish the stack and rolled it back" (`ACCOUNT_ACCESS_STACK_FAILED`) | Usually a person without IAM permissions, a name clash, or an SCP | Delete the failed stack, fix the permission, try again |
| "The stack is in a different AWS account" (`ACCOUNT_ACCESS_WRONG_ACCOUNT`) | Signed in to another account | Sign in to the account you entered, open AWS again |
| "The stack in AWS isn't the template Diakrin gave you" (`ACCOUNT_ACCESS_TEMPLATE_MISMATCH`) | Template or parameters were changed | Choose **Update in AWS** |
| "A role in AWS trusts something other than Diakrin" (`ACCOUNT_ACCESS_TRUST_MISMATCH`) | Trust edited, a permissions boundary added, or a role deleted and recreated | Choose **Update in AWS**; a recreated role may need a new connection |
| "A role in AWS has permissions that differ from the template" (`ACCOUNT_ACCESS_POLICY_MISMATCH`) | A policy or attachment was edited | Choose **Update in AWS** |
| `ACCOUNT_ACCESS_UPGRADE_REQUIRED` | Access version before 1.1.0 | Install the new per-connection stack and verify |
| "AWS could not be reached. Nothing was changed; try again." (`CLOUD_UNAVAILABLE`) | AWS error on Diakrin's side of the call | Try again; the connection is not marked invalid |
| "A setup still uses this account. Archive its setups first." (`CLOUD_ACCOUNT_IN_USE`) | Changing the home region or removing an account that setups use | Archive the setups first |
| Setup: `CONNECTION_VERIFICATION_REQUIRED` | The 15-minute connection proof expired or is stale | Choose **Create** again; it re-verifies |
| Setup: `FOUNDATION_EXISTS` | A foundation with that identity already exists | An existing foundation cannot be imported or adopted; use a new setup |
| Setup stack failed with `ACCESS_DENIED` and an action name | A policy denies that action | See [Organization policies](#organization-policies) |
| Setup stack failed with `SERVICE_LINKED_ROLE_NOT_READY` | The service-linked role was not visible yet | Run the command in [Service-linked roles](#service-linked-roles) |
| Setup runtime stack rolled back, VPC reused | An unrouted internet gateway is attached | See [Network](#network) |
| Update link says "The AWS stack is already up to date." | `UPDATE_NOT_NEEDED` | Nothing to update |
| After connect, "Setups keep running" but the account shows an error | The stack or roles are gone | Create the stack again to restore it |

## Next

Continue to [Set up your company cloud](/docs/company-cloud) to create the setup, or compare with [Connect Google Cloud and create a setup](/docs/connect-gcp).
