Docs / Setting up the role

Setting up the role

Add AWS accounts to AccessLens and create its one read-only role in each: one-click, CloudFormation, a StackSet for many accounts, Terraform or the AWS CLI.

Updated

AccessLens needs one IAM role in each account it scans: AccessLensReadOnly, with one inline read-only policy, AccessLensReadOnlyPolicy. It creates nothing else. The exact policies and templates are on What it installs; this page walks through setting it up.

Add accounts

  • By ID. Go to Accounts → Add account and enter the 12-digit account ID and, optionally, an alias.
  • From AWS Organizations. If your SSO identity can see the organization's management account or a delegated administrator, choose Import from AWS Organizations and pick accounts. Importing only stores them in AccessLens; nothing changes in AWS.

Each account gets its own ExternalId: 32 random hex characters from your operating system's secure random generator, stored locally and shown in the wizard. You can regenerate it under the account's settings; afterwards, update the role's trust policy with the setup wizard. To deploy the role to many accounts with one StackSet, you can opt in to one ExternalId for the organization instead; see Many accounts: a StackSet.

The role name defaults to AccessLensReadOnly. Change it per account only if you created the role under another name.

The setup wizard

Accounts → Set up access walks through five steps: Role, Review policies, Create the role, Verify and First scan.

  1. Role. Choose how to create the role: Create it for me, CloudFormation, Terraform or AWS CLI.
  2. Review policies. Tabs show the trust policy, the permissions policy, Why these permissions? (an explanation of each permission group) and, for one-click create, the exact API calls that will be made.
  3. Create the role. Deploy the template yourself, or confirm one-click create (below).
  4. Verify. AccessLens assumes the role with the account's ExternalId and makes one cheap read per permission group, reporting each as Works, Denied, Not applicable (for example, Organizations in a standalone account) or Error. A role created moments ago is retried for up to 20 seconds while IAM makes it usable.
  5. First scan. When the account is ready, Scan this account now starts the first scan and opens the Scans page.

Deploy it yourself

  • CloudFormation: deploy the YAML as a stack in the target account (suggested name accesslens-readonly-role).
  • Terraform: an aws_iam_role and an aws_iam_role_policy, with the policies as heredocs.
  • AWS CLI: a bash script that runs create-role and put-role-policy; run it with credentials for the target account.

Then choose I've created it: verify access. The templates are on What it installs.

Many accounts: a StackSet

Accounts → Roll out with StackSets generates a template for a service-managed CloudFormation StackSet that creates the same role in every account of the OUs you choose, and the AWS CLI commands to create the StackSet and deploy it. You run them in the organization's management account (or a CloudFormation delegated administrator, with --call-as DELEGATED_ADMIN); trusted access for StackSets must be on in AWS Organizations. With auto-deployment on, accounts added to those OUs later get the role too. AccessLens still creates nothing itself.

A StackSet deploys one template everywhere, so it needs one organization-wide ExternalId. It's off until you turn it on, and the dialog explains the trade-off first: if the value leaks, it's valid in every account that uses it, not just one. The trust policy still admits only your hub's IAM Identity Center role for the chosen permission set (and your organization, when it's known), so the ExternalId alone doesn't let anyone in.

While it's on, accounts you import from AWS Organizations use it, and you can apply it to accounts you imported earlier. Accounts you set up one at a time keep their own. Replace it gives every account that used it the new value, and they show Not verified until you update the StackSet. Service-managed StackSets never deploy to the management account itself, so set that account up like any other.

The StackSet template and commands are on What it installs.

One-click create

If one of your permission sets in the target account can call iam:CreateRole and iam:PutRolePolicy, AccessLens can create the role. This is the only write it ever makes to AWS.

  1. In the Role step, choose Create it for me.
  2. Review policies: the role name, both policies and the API calls.
  3. In Create the role, choose that permission set, tick the confirmation and type the account ID.
  4. Choose Create role in AWS.

Before writing, AccessLens checks that the plan's SHA-256 digest matches what you previewed, that the typed account ID is the target, and that sts:GetCallerIdentity confirms the credentials belong to that account. The role name is part of the digest, so renaming after a preview means previewing again.

It's idempotent: an existing role with the same trust policy is reused, and the inline policy is written only if it's missing or different. It attaches no managed policies, creates no policy objects, adds no tags and deletes nothing.

If the role already exists

A role with the chosen name and a different trust policy is never modified or deleted. The wizard shows that role's trust policy and offers two ways forward:

  • Use a different name. Saves a new role name for the account (suggested: AccessLensReadOnly-2), then you review and create again.
  • Delete it yourself, then retry. The wizard shows an AWS CLI script that removes the role's inline policies, managed-policy attachments and instance-profile memberships, then deletes it. AccessLens never runs it. Check that nothing else uses the role first.

Readiness

Verifying and scanning both update an account's readiness:

ReadinessMeaning
ReadyThe role can be assumed and every permission group works.
Partial accessThe role works but some permission groups are denied. Scans run; rules that need the missing permissions are skipped.
Role not assumableAccessLens couldn't assume the role. Check the trust policy, the ExternalId and the role name.

An older role keeps working after an AccessLens update adds permissions: only the rules that need the new reads are reported as not evaluated. Re-run one-click create, or update your stack, to add them.

Remove access

Use How to remove access at the bottom of the wizard, or the removal commands on What it installs. Delete the role and nothing else remains. Removing an account inside AccessLens only deletes its local data and never calls AWS.

Direct SSO fallback

If you can't create the role, an account can be scanned with an Identity Center permission set's own credentials: Accounts → Settings → Use an SSO permission set directly (fallback). This works only if that permission set grants the reads AccessLens needs; missing permissions show up as skipped analyzers. The accounts list labels this mode as a fallback.