

# Cross-account assessments

An AWS Assurance environment assesses resources in the account that owns it. The workload you assess might span more than one account. If those accounts are not members of an AWS Organizations organization that you have connected to the environment, use cross-account connections. For organization environments, see [AWS Assurance and AWS Organizations](organizations.md) instead.

A cross-account connection is established by consent from both sides. The account that owns the environment sends an invitation, and the invited account accepts it. Neither side can establish the connection alone: the owning account cannot add an account that has not accepted, and the invited account cannot join an environment it was not invited to.

Throughout this section, the *owning account* is the account that contains the AWS Assurance environment, and the *connected account* is the account you invite. After the connected account accepts the invitation, AWS Assurance includes the connected account’s resources in the environment’s inventory and in its assessments. A framework-level or control-level assessment evaluates every active connected account, in the same way it evaluates the owner account. For more information, see [Account coverage](assessments.md#assessments-account-coverage).

**Topics**
+ [How cross-account assessments work](#how-cross-account-assessments-work)
+ [Prerequisites](#cross-account-prerequisites)
+ [Setting up a cross-account connection](#setting-up-a-cross-account-connection)
+ [How AWS Assurance reads resources in connected accounts](#how-resource-discovery-works-across-connected-accounts)
+ [Managing invitations and connections](#managing-invitations-and-connections)
+ [Cross-account connections and AWS Organizations](#cross-account-connections-and-aws-organizations)
+ [Troubleshooting a cross-account connection](#troubleshooting-a-cross-account-connection)

## How cross-account assessments work
<a name="how-cross-account-assessments-work"></a>

When the connected account accepts an invitation, AWS Assurance creates the service-linked role `AWSServiceRoleForAssurance` in that account, or uses the role if it already exists. AWS Assurance then sets up configuration recording in the account. You don’t create or configure an IAM role for the connection. For more information about the role, see [Service-linked roles for AWS Assurance](setting-up.md#setting-up-slr).

The connection moves through the following states:

 `PENDING`   
The owning account has sent the invitation, and the invited account hasn’t accepted it yet.

 `ACTIVE`   
The invited account has accepted the invitation. The account’s resources are included in the environment’s inventory and in assessments.

 `REJECTED`   
The invited account declined the invitation.

 `REVOKED`   
The owning account withdrew the invitation, or removed an established connection.

 `EXPIRED`   
The invitation wasn’t accepted within 7 days.

AWS Assurance uses only `ACTIVE` connections. It doesn’t read resources from an account whose connection is in any other state.

## Prerequisites
<a name="cross-account-prerequisites"></a>

Before you set up a cross-account connection, confirm the following:
+ You have an AWS Assurance environment in the owning account.
+ The account you invite is a different account from the owning account. You cannot invite the owning account to its own environment.
+ The environment is not an organization environment. Cross-account connections and organization environments are mutually exclusive. For details, see [Cross-account connections and AWS Organizations](#cross-account-connections-and-aws-organizations).

### Permissions for inviting and accepting
<a name="cross-account-permissions"></a>

The owning account needs `assurance:CreateInvitation` to send an invitation. The connected account needs `assurance:AcceptInvitation` and `iam:CreateServiceLinkedRole` to accept it.

## Setting up a cross-account connection
<a name="setting-up-a-cross-account-connection"></a>

The owning account sends the invitation, and the connected account accepts it in the same AWS Region as the environment. An invitation expires 7 days after you send it.

**To invite an account in the console**

1. Open the [AWS Assurance console](https://console.aws.amazon.com/assurance/), and then choose **Environments**.

1. Choose your environment.

1. In the **Invited accounts** section, choose **Invite account**.

1. For **Invited AWS account IDs**, enter one or more 12-digit account IDs, one per line or separated by commas.

1. Choose **Send invitation**.

**To accept an invitation in the console**

1. In the connected account, open the AWS Assurance console in the Region of the environment, and then choose **Invitations**.

1. For the invitation, choose **Accept/Reject**.

1. Choose **Accept**.

The connection becomes `ACTIVE`, and AWS Assurance begins to include the connected account’s resources in the environment’s inventory. To decline the invitation instead, choose **Reject**.

To set up the connection with the API, call the following operations:

1. In the owning account, call `CreateInvitation` with the Amazon Resource Name (ARN) of the environment and the account ID that you want to add. The response returns the invitation status and, for a new `PENDING` invitation, the time it expires.

    `CreateInvitation` is idempotent for a given environment and invited account. If you call it for an account that already has a live invitation or an established connection, AWS Assurance returns the existing state rather than creating a second record. A call for an account whose previous invitation was rejected, revoked, or expired resets that record to a new `PENDING` invitation.

1. In the connected account, call `ListInboundInvitations` to list the invitations sent to your account. This operation lists only the invitations for your account, so you don’t supply an environment ARN.

1. In the connected account, call `AcceptInvitation` with the environment ARN.

1. To confirm the connection, call `ListOutboundInvitations` with the environment ARN from the owning account, or call `GetInvitation`. A status of `ACTIVE` confirms that the connection is established.

To decline an invitation, the connected account calls `RejectInvitation` with the environment ARN. `RejectInvitation` applies only to a `PENDING` invitation. To leave an established connection, ask the owning account to remove it with `DeleteInvitation`.

## How AWS Assurance reads resources in connected accounts
<a name="how-resource-discovery-works-across-connected-accounts"></a>

For an environment that has cross-account connections, the inventory covers the owning account and every account whose connection is `ACTIVE`. AWS Assurance reads each account through the service-linked role `AWSServiceRoleForAssurance` in that account. It doesn’t include accounts whose connections are pending, rejected, revoked, or expired.

After a connection becomes `ACTIVE`, and after you add Regions to the environment, AWS Assurance sets up configuration recording. In each Region of the environment scope where the connected account doesn’t have an AWS Assurance service-linked configuration recorder, AWS Assurance creates one. A failure in one Region doesn’t affect other Regions or other accounts.

## Managing invitations and connections
<a name="managing-invitations-and-connections"></a>

In the console, the **Invited accounts** section of the environment page lists the accounts that you invited and the status of each invitation. To withdraw an invitation or remove a connection, select the account, and then choose **Revoke**.

You can also use the following operations.

 **From the owning account:** 

 `ListOutboundInvitations`   
Lists the invitations you sent for one environment. Supply the environment ARN. You can filter by status and page through results.

 `GetInvitation`   
Returns the details of one invitation, including its status and when it was created, last updated, and expires. Supply the environment ARN and the connected account ID.

 `DeleteInvitation`   
Removes an invitation or a connection. Supply the environment ARN and the connected account ID. This is the only owner-side teardown operation, and it applies in any state: it withdraws an invitation that is still pending, and it unlinks an account whose connection is `ACTIVE`. AWS Assurance moves the record to `REVOKED` and no longer includes the account’s resources in the environment’s inventory or assessments.

 **From the connected account:** 

 `ListInboundInvitations`   
Lists the invitations sent to your account across all environments. This operation lists only the invitations for your account, so you don’t supply an environment ARN. You can filter by status and page through results.

 `GetInvitation`   
Returns the details of an invitation sent to your account. Supply the environment ARN.

 `AcceptInvitation`   
Accepts an invitation. Supply the environment ARN.

 `RejectInvitation`   
Declines a pending invitation. Supply the environment ARN. This operation applies only while the invitation is `PENDING`. To end an established connection, ask the owning account to call `DeleteInvitation`.

Removing a connection doesn’t delete the service-linked role or the AWS Assurance configuration recorder in the connected account. To delete the role, see [Deleting the service-linked role](setting-up.md#setting-up-slr-delete).

## Cross-account connections and AWS Organizations
<a name="cross-account-connections-and-aws-organizations"></a>

An environment uses either cross-account connections or AWS Organizations scope. It cannot use both. In an organization environment, AWS Assurance reaches member accounts through the service-linked role in each account, so invitations aren’t used. For more information, see [Organization environments and cross-account access](organizations.md#organizations-cross-account).

AWS Assurance enforces this in both directions:
+ You cannot invite an account to an environment that has Organizations scope enabled. `CreateInvitation` returns a validation error stating that member accounts are accessed through the service-linked role.
+ You cannot enable Organizations scope on an environment that has cross-account connections. `UpdateEnvironment` returns a validation error. This check covers pending invitations as well as active connections, because an outstanding invitation is an access path the invited account can still accept.

To move an environment from cross-account connections to Organizations scope, remove every connection and withdraw every outstanding invitation with `DeleteInvitation` first, then enable Organizations scope.

The environment’s inventory follows the same split. For an organization environment, the inventory covers the organization’s member accounts in scope and doesn’t use cross-account connections. For an environment without Organizations scope, the inventory covers the owning account plus the accounts with `ACTIVE` connections.

## Troubleshooting a cross-account connection
<a name="troubleshooting-a-cross-account-connection"></a>

You might encounter the following errors:
+ A validation error stating that the invitation has expired means that it wasn’t accepted within 7 days. Ask the owning account to send a new invitation.
+ A validation error stating that the invitation is no longer valid means that the invitation was rejected or revoked. Ask the owning account to send a new invitation.
+ A validation error stating that the invitation can’t be accepted means that the environment is no longer available. Ask the owning account to confirm the environment.
+ A validation error that asks you to ensure that the caller is permitted to call `iam:CreateServiceLinkedRole` means that you don’t have permission to create the service-linked role. Grant the permission, and then accept the invitation again.
+ A conflict error on `RejectInvitation` means the invitation is not `PENDING`. An established connection is removed by the owning account with `DeleteInvitation`.

If a connection is `ACTIVE` but resources in the connected account don’t appear in the inventory or in assessment results, check that the Regions you expect are in the environment scope.