# Setting up an EventBridge integration

### 1. **Create a Standard AWS SQS queue**

1. Log in to the [AWS Console](https://console.aws.amazon.com/).
2. Open `Amazon SQS` from the Services dropdown or the Services search bar at the top of the page.
3. Click `Create queue`.
4. Select **Standard** queue type.
5. Give your SQS queue a name, and click `Create queue`.
6. Make note of the ARN of the newly created queue.

### **2. Contact your Rightsline representative**

1. Provide them with your *AWS Account ID* and the *AWS region* that you would like to set up your EventBridge integration.
2. Your Rightsline representative will provide you with your AWS EventBridge **event source name**.  You will use this name to create your AWS EventBridge event bus.

### 3. Create an AWS EventBridge event bus (AWS CLI)

Because the event bus name has to start with `aws.partner/rightsline.com/` it cannot be created in the UI.  You must create your AWS EventBridge event bus via the AWS CLI.  To do so, run the following commands:

```
aws events create-event-bus --name aws.partner/rightsline.com/{{EVENT_SOURCE_NAME}} --event-source-name aws.partner/rightsline.com/{{EVENT_SOURCE_NAME}} --region {{REGION}}
```

At this point the remainder of the setup can continue to be done via the CLI or you can scroll down to see how it can be set up in the Console.

In the above command, replace `{{EVENT_SOURCE_NAME}}` with the event source name provided by Rightsline in the [second section](#contact-your-rightsline-representative) above.  Replace `{{REGION}}` with the desired region provided to Rightsline in the [second section](#contact-your-rightsline-representative) above.

```
aws events put-rule --cli-input-json file://rule.json --region {{REGION}}
```

In the above command, replace `{{REGION}}` with the desired region provided to Rightsline in the [second section](#contact-your-rightsline-representative) above.  The file://rule.json file must exist in the directory you are running the command.  The file should look like the following:

{% code title="rule.json" %}

```json
{
    "Description": "Rule Description",
    "EventBusName": "aws.partner/rightsline.com/{{EVENT_SOURCE_NAME}}",
    "EventPattern": "{\"source\": [{\"prefix\": \"aws.partner/rightsline.com/{{EVENT_SOURCE_NAME}}\"}]}",
    "Name": "RuleName",
    "State": "ENABLED"
}
```

{% endcode %}

In the above command, replace `{{EVENT_SOURCE_NAME}}` with the event source name provided by Rightsline in the [second section](#contact-your-rightsline-representative) above.

```
aws events put-targets --cli-input-json file://targets.json --region {{REGION}}
```

In the above command, replace `{{REGION}}` with the desired region provided to Rightsline in the [second section](#contact-your-rightsline-representative) above.  The `file://targets.json` file must exist in the directory you are running the command.  The file should look like the following:

{% code title="targets.json" %}

```json
{
    "Rule": "RuleName",
    "EventBusName": "aws.partner/rightsline.com/{{EVENT_SOURCE_NAME}}",
    "Targets": [{
            "Id": "1",
            "Arn": "{{SQS_QUEUE_ARN}}"
        }
    ]
}
```

{% endcode %}

In the above command, replace `{{EVENT_SOURCE_NAME}}` with the event source name provided by Rightsline in the [second section](#contact-your-rightsline-representative) above.  Replace `{{SQS_QUEUE_ARN}}` with the SQS queue ARN from the [first section](#create-an-aws-sqs-queue) above.

**Create an AWS EventBridge Rule (Console)**

Once the steps above have been completed to create the event bus via the CLI, the Rule setup can happen in the console as follows:

1. Open `Rules` in the left sidebar menu.
2. Select your new Event bus from the dropdown, and click `Create rule`.
3. Give your rule a name, and make sure ***Rule with an event pattern*** is selected. Click `Next`.
4. Under Event source, select ***AWS events or EventBridge partner events***.

<figure><img src="https://1230650179-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGAeYsGmflcmJcE_7Ap-3778137224%2Fuploads%2FhqeFakZ3UP9eESLrpXNt%2Fevb_source.JPG?alt=media&#x26;token=45f23963-1b94-4946-bcbd-bfaff2ae6d65" alt=""><figcaption><p>Rightsline event source</p></figcaption></figure>

10. Under Event pattern, select ***EventBridge*** ***partners***, and select ***Rightsline*** as the partner.  For Event type, select ***All Events.***  Click `Next`***.***

<figure><img src="https://1230650179-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGAeYsGmflcmJcE_7Ap-3778137224%2Fuploads%2FiW85rzYVI2bSfdeA2jRt%2Fevb_pattern.JPG?alt=media&#x26;token=bf7ab428-27f3-4627-a659-98cbb6348282" alt=""><figcaption><p>Rightsline event pattern</p></figcaption></figure>

11. Under Target 1, select ***AWS service***, ***SQS queue***, and the queue name created from the [first section](#create-an-aws-sqs-queue). Click `Next`.
12. Add any relevant Tags. Click `Next`.
13. Click `Create Rule`.

### 4. Granting access for your SQS queue to receive messages from the Event Bus Rule

Once the SQS queue, the Event Bus, and the Event Bus Rule are created, you need to modify the access policy on the SQS queue to allow it to receive messages from your new Event Bus Rule.  Navigate to your new SQS queue in the AWS Console, click on **Access Policy**, then **Edit**.  Your access policy will need to include the following Statement:

```json
{
  "Sid": "sampleStatment",
  "Effect": "Allow",
  "Principal": {
    "Service": "events.amazonaws.com"
  },
  "Action": "sqs:SendMessage",
  "Resource": "{{SQS_QUEUE_ARN}}",
  "Condition": {
    "ArnEquals": {
      "aws:SourceArn": "{{EVENT_BUS_RULE_ARN}}"
    }
  }
}
```

In the above Statement, replace `{{SQS_QUEUE_ARN}}` with the ARN of the SQS queue, and `{{EVENT_BUS_RULE_ARN}}` with the ARN of the Event Bus Rule.  This should grant your new Event Bus Rule to forward messages to your SQS queue.&#x20;
