

# Connecting Agent Spaces in a constellation

This topic explains how to connect two Agent Spaces in a constellation. Before you start, read [Agent Space Constellations](configuring-integrations-and-knowledge-agent-space-constellations-index.md) to choose the relationship type and to understand what a connection grants.

A connection has two sides. The owner of each Agent Space creates their own side, and the connection becomes **Active** after both sides exist.

## Prerequisites
<a name="prerequisites"></a>

Before you connect Agent Spaces, make sure that you have the following:
+ The Agent Spaces that you want to connect. They can be in the same AWS account or in different accounts. They can be in the same AWS Region or in different AWS Regions within the `aws` partition. Agent Space Constellations isn't available in AWS GovCloud (US).
+ The Amazon Resource Name (ARN) of the other Agent Space. If you don't own the other Agent Space, ask its owner for the ARN. To copy the ARN, the owner opens the [AWS Ops Agent console](https://console.aws.amazon.com/devops-agent/), opens their Agent Space, chooses **Actions**, and then chooses **Copy ARN**.
+ An agreement with the owner of the other Agent Space on the relationship type and on the role of each side.
+ AWS Identity and Access Management (IAM) permissions to create or pass an IAM role in your account.

## Step 1: Set up the constellation role
<a name="step-1-set-up-the-constellation-role"></a>

In this step, you set up the role that your Agent Space uses to call the other Agent Space. The *constellation role* is the IAM role that AWS Ops Agent assumes when your Agent Space calls another Agent Space. With a dedicated role, the cross-Agent Space permissions stay separate from your other permissions.

Each Agent Space in a constellation needs its own constellation role. You need a role on both sides of every connection, including the dependency side.

You can have the console create the role when you create the connection, or you can create the role yourself.

### Option A: Have the console create the role
<a name="option-a-have-the-console-create-the-role"></a>

Choose this option if you don't manage IAM roles with infrastructure as code. In [Step 3: Create your side of the connection](#step-3-create-your-side-of-the-connection), on the **Register role** page, choose **Auto-create a new Ops Agent role**. You get a role named `DevOpsAgentRole-Constellation-suffix`, where *suffix* is a value that the console adds to the name. The role has the AWS managed policy `AIDevOpsConstellationAccessPolicy` attached. If either Agent Space uses a customer managed key, you must also add the AWS KMS permissions in [Step 2](#step-2-add-permissions-for-agent-spaces-encrypted-with-a-customer-managed-key) to this role.

### Option B: Create the role yourself
<a name="option-b-create-the-role-yourself"></a>

Choose this option if you manage IAM roles with infrastructure as code. Use a dedicated role for each Agent Space, and don't reuse the monitoring role of the Agent Space. A dedicated role makes AWS CloudTrail events easier to attribute.

The role needs a trust policy and a permissions policy:
+ **Trust policy** – With this policy, `aidevops.amazonaws.com` can call `sts:AssumeRole` and `sts:TagSession`, scoped to your Agent Space.
+ **Permissions policy** – The AWS managed policy `AIDevOpsConstellationAccessPolicy` contains the operations in the constellation permission set. Use the same policy in every Agent Space of every connection. For each call, AWS Ops Agent applies a session policy that limits the role to the operations that the relationship allows. For example, a dependency's session can only call `aidevops:GetAgentSpace` on its consumer.

The trust policy uses the following placeholder values. Replace them with your own values:
+ *`123456789012`* – Your AWS account ID. It appears in both `aws:SourceAccount` and `aws:SourceArn`.
+ *`us-east-1`* – The AWS Region of your Agent Space.
+ *`agent-space-id`* – The ID of your Agent Space.

With these values replaced, the `aws:SourceArn` value is the ARN of your Agent Space.

```
{
  "Version": "2012-10-17",		 	 	 		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "aidevops.amazonaws.com"
      },
      "Action": [
        "sts:AssumeRole",
        "sts:TagSession"
      ],
      "Condition": {
        "StringEquals": {
          "aws:SourceAccount": "123456789012",
          "aws:SourceArn": "arn:aws:aidevops:us-east-1:123456789012:agentspace/agent-space-id"
        }
      }
    }
  ]
}
```

#### To create the role
<a name="to-create-the-role"></a>

1. Open the AWS Identity and Access Management (IAM) console at [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/).

1. Create an IAM role with the trust policy, using your values for the placeholders.

1. Attach the AWS managed policy `AIDevOpsConstellationAccessPolicy` to the role.

The role appears in the IAM console with the trust policy and the managed policy. If you can't create the role, check that you have permission to create IAM roles in your account.

In [Step 3: Create your side of the connection](#step-3-create-your-side-of-the-connection), on the **Register role** page, choose **Assign an existing role**, and then choose this role.

## Step 2: Add permissions for Agent Spaces encrypted with a customer managed key
<a name="step-2-add-permissions-for-agent-spaces-encrypted-with-a-customer-managed-key"></a>

In this step, you give the calling Agent Space permission to decrypt the data of an Agent Space that a customer managed key encrypts. Skip this step if neither Agent Space uses a customer managed key in AWS Key Management Service (AWS KMS).

If an Agent Space's data is encrypted with a customer managed AWS KMS key, the other Agent Space needs permission to decrypt that data. The AWS managed policy `AIDevOpsConstellationAccessPolicy` doesn't grant any AWS KMS permissions, and the console doesn't add them to the roles that it creates. In this step, you add two permissions yourself: an inline policy on the constellation role of the calling Agent Space, and a statement in the key policy of the encrypted Agent Space. Without both, calls into the encrypted Agent Space fail even when the connection is **Active**. For more information about customer managed keys, see [Encryption at rest for AWS Ops Agent](aws-devops-agent-security-encryption-at-rest-for-devops-agent.md).

This step uses the following terms:
+ The *calling Agent Space* opens investigations in, or reads from, the other Agent Space.
+ The *encrypted Agent Space* has its data encrypted with a customer managed key.

The relationship determines which Agent Space is the calling Agent Space, as shown in the following table.


| Relationship | Encrypted Agent Space | Calling Agent Space | 
| --- | --- | --- | 
| Lead and encrypted member | Member | Lead | 
| Member and encrypted lead | Lead | Member, so that the member can escalate | 
| Consumer and encrypted dependency | Dependency | Consumer | 
| Both Agent Spaces encrypted | Both | Both. Each key policy allows the other Agent Space's account. | 

You add an inline policy to the constellation role of the calling Agent Space. Add this policy even if the console creates the role, because the managed policy `AIDevOpsConstellationAccessPolicy` doesn't include `kms:Decrypt`. If you chose [Option A](#option-a-have-the-console-create-the-role), the role doesn't exist yet. Add the key policy statement now, and add the inline policy to the role after Step 3 creates it. The `kms:ViaService` condition limits the permission to calls that AWS Ops Agent makes. The encryption context condition limits it to data that belongs to an Agent Space.

Add the following inline policy to the constellation role of the calling Agent Space.

```
{
  "Version": "2012-10-17",		 	 	 		 	 	 
  "Statement": [
    {
      "Sid": "AllowConstellationPeerCmkDecryptViaDevOpsAgent",
      "Effect": "Allow",
      "Action": "kms:Decrypt",
      "Resource": "arn:aws:kms:*:*:key/*",
      "Condition": {
        "StringLike": {
          "kms:ViaService": "aidevops.*.amazonaws.com",
          "kms:EncryptionContext:aws-crypto-ec:aws:aidevops:arn": "arn:aws:aidevops:*:*:agentspace/*"
        }
      }
    }
  ]
}
```

Add the following statement to the key policy of the encrypted Agent Space. The statement uses two placeholder values. Replace *`123456789012`* with the account ID of the calling Agent Space, and replace *`us-east-1`* with the AWS Region of the encrypted Agent Space.

```
{
  "Sid": "AllowConstellationPeerViaDevOpsAgent",
  "Effect": "Allow",
  "Principal": {
    "AWS": "arn:aws:iam::123456789012:root"
  },
  "Action": "kms:Decrypt",
  "Resource": "*",
  "Condition": {
    "StringEquals": {
      "kms:ViaService": "aidevops.us-east-1.amazonaws.com"
    }
  }
}
```

### To add the permissions
<a name="to-add-the-permissions"></a>

1. In the account of the calling Agent Space, open the IAM console at [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/).

1. Add the inline policy to the constellation role of the calling Agent Space.

1. In the account of the encrypted Agent Space, open the AWS KMS console at [https://console.aws.amazon.com/kms](https://console.aws.amazon.com/kms).

1. Add the key policy statement, with your values for the placeholders, to the key policy of the customer managed key of the encrypted Agent Space.

After you add both permissions, AWS Ops Agent can decrypt the encrypted Agent Space's data when the calling Agent Space calls it.

## Step 3: Create your side of the connection
<a name="step-3-create-your-side-of-the-connection"></a>

In this step, you create the connection from your Agent Space to the other Agent Space. Before you start, complete Step 1. If either Agent Space uses a customer managed key, also complete Step 2. If the console creates the role, add the Step 2 inline policy to that role after you create the connection.

The connection wizard has three pages: **Specify connection**, **Register role**, and **Review and create**.

### To open the connection wizard
<a name="to-open-the-connection-wizard"></a>

1. Open the AWS Ops Agent console.

1. Choose **Agent Spaces**.

1. Select the Agent Space that you want to connect.

1. Choose the **Constellations** tab.

1. In the upper-right corner of the **Agent Space Constellations** panel, choose **Create connection**.

On the **Specify connection** page, choose the role that your Agent Space plays toward the other Agent Space. For what each role does, see [Relationship types](configuring-integrations-and-knowledge-agent-space-constellations-index.md#relationship-types).
+ **Connect as lead** – The other Agent Space is your member.
+ **Connect as member** – The other Agent Space is your lead. This option isn't available if your Agent Space already has a lead.
+ **Connect as consumer** – The other Agent Space is your dependency.
+ **Connect as dependency** – The other Agent Space is your consumer.

### To specify the connection
<a name="to-specify-the-connection"></a>

1. For **Target agent space ARN**, enter the ARN of the other Agent Space.

1. Under **Connection role**, select the role that your Agent Space plays toward the other Agent Space.

1. Choose **Next**.

On the **Register role** page, you choose the constellation role for your Agent Space:
+ **Auto-create a new Ops Agent role** – The console creates the constellation role for you, and the page shows the name of the role. For details, see [Option A: Have the console create the role](#option-a-have-the-console-create-the-role).
+ **Assign an existing role** – You use the role that you created in [Option B: Create the role yourself](#option-b-create-the-role-yourself).

The **Register role** page has an **IAM role** section. Under **Choose a role option**, it lists **Auto-create a new Ops Agent role** and **Assign an existing role**. When you choose **Auto-create a new Ops Agent role**, a message shows the name of the role that the console creates. The page also has **Cancel**, **Previous**, and **Next** buttons.

### To register the role and create the connection
<a name="to-register-the-role-and-create-the-connection"></a>

1. On the **Register role** page, select **Auto-create a new Ops Agent role** or **Assign an existing role**.

1. If you selected **Assign an existing role**, choose the role that you created in [Option B: Create the role yourself](#option-b-create-the-role-yourself).

1. Choose **Next**.

1. On the **Review and create** page, review the details.

1. Choose **Create connection**.

The connection appears in the **Connections** table with the status **Pending**. It stays **Pending** until the owner of the other Agent Space creates their side. If you can't create the connection, check that the ARN is correct and that you have the IAM permissions listed in [Prerequisites](#prerequisites).

## Step 4: Create the other side of the connection
<a name="step-4-create-the-other-side-of-the-connection"></a>

In this step, the owner of the other Agent Space creates their side of the connection. Both sides must create the connection before it becomes **Active**.

The other side must choose the role that complements yours. The following table shows the complementary role for each choice.


| Your choice | The other side's choice | 
| --- | --- | 
| Connect as lead | Connect as member | 
| Connect as member | Connect as lead | 
| Connect as consumer | Connect as dependency | 
| Connect as dependency | Connect as consumer | 

After you agree on the roles, do the following.

### To have the other side create the connection
<a name="to-have-the-other-side-create-the-connection"></a>

1. Open your Agent Space, choose **Actions**, and then choose **Copy ARN**.

1. Send the ARN of your Agent Space to the owner of the other Agent Space.

1. Ask the owner to complete [Step 1: Set up the constellation role](#step-1-set-up-the-constellation-role), [Step 2](#step-2-add-permissions-for-agent-spaces-encrypted-with-a-customer-managed-key) if either Agent Space uses a customer managed key, and [Step 3: Create your side of the connection](#step-3-create-your-side-of-the-connection) in their Agent Space. For **Target agent space ARN**, they enter the ARN of your Agent Space.

1. Confirm with the owner that they selected the complementary role from the preceding table.

## Step 5: Verify the connection
<a name="step-5-verify-the-connection"></a>

In this step, you confirm that the connection is active and points in the right direction.

After both owners create their sides, the status changes to **Active** on both sides. The status can take several minutes to change. The **Connections** table doesn't refresh on its own. To see the current status, choose the refresh button above the table.

The **Role of connected space** column shows the role of the other Agent Space, not your own. For example, in a member Agent Space, the connection to its lead shows **Lead**.

Before you add more connections, verify the following:

1. The lead lists each of its members, and each member lists its lead.

1. Each consumer lists its dependencies, and each dependency lists its consumers.

1. The direction of each connection matches the way that your teams handle incidents.

## Next steps
<a name="next-steps"></a>
+ To troubleshoot a connection that stays **Pending**, or to manage your connections, see [Managing constellation connections](agent-space-constellations-managing-constellation-connections.md).