# Connect CostGuard for AWS

Finout's CostGuard module provides actionable cost optimization insights. CostGuard scans surface idle resources, rightsizing opportunities, and offers commitment purchase recommendations. In order to do this, CostGuard needs read only permissions to certain metrics.\
The role created during the standard AWS cost data integration has the necessary permissions to perform CostGuard scans and discover linked accounts within the master payer account. However, to run CostGuard scans for resources within linked accounts, you need to create a CloudFormation StackSet that applies the necessary configurations across all linked accounts.&#x20;

{% hint style="warning" %}
**Important**: This onboarding procedure assumes that the AWS account has already been onboarded. If it has not, please follow the procedure outlined in [Connect to AWS](https://docs.finout.io/billing-integrations/cloud-providers/connect-to-aws), as per the instructions.
{% endhint %}

There are two options to Connect CostGuard for AWS:

* [Create a New CloudFormation StackSet](#h_b69c0313e2)
* [Add Permissions Manually](#h_a55a679675)

## Create a New CloudFormation StackSet  <a href="#h_b69c0313e2" id="h_b69c0313e2"></a>

{% hint style="info" %}
This procedure applies to AWS Multi-Accounts.
{% endhint %}

1. Open the [AWS CloudFormation console](https://console.aws.amazon.com/cloudformation).<br>

   <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2FjcyMtcjK175K93FpA4i7%2Fimage.png?alt=media&#x26;token=ae480c5b-9f5d-489f-bee2-533db2a9e4a2" alt=""><figcaption></figcaption></figure>

<figure><img src="https://finout.intercom-attachments.eu/i/o/6521885/784fe4f9c76f681871dd9290/PUoEJ00azHmGcPHkzMGE4iuB1j0uaOLmjNyCDSQ-PF6eIYRnF6VWm-euNIvkK8O2Gd3Hb9zfJTKylLsItqjEeoP_0dJcqAU4-p2dESZPS8-97C9vspwrBhH-qATaQaoM53Y7Shv213mReOI1ySbmO-c?expires=1727763300&#x26;signature=54e94573b7758da442a3990b1d129aa2973c9ad0dfca281fa796bc97fe206f2d&#x26;req=1tBtxFDyqXsp0xr0v9tnpH3N0fXNAoS%2FGDX%2FtWjl3Pjcog4jw9Z0II%2BfGVhm%0AAWx4iTTP9CdUAz8%3D%0A" alt=""><figcaption></figcaption></figure>

2. Choose **StackSet** from the navigation on the left-hand side of the scree&#x6E;**.**\
   ![](https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2FwoyBawaQG1sxj9juir5M%2Fimage.png?alt=media\&token=d9c42255-5b6d-45fc-b0e3-7eb78fce274a)\
   The **Specify StackSet details** step appears.

<figure><img src="https://finout.intercom-attachments.eu/i/o/6521886/4b1f790af36f84983aa8e174/52U290KjDdSzEV3pYs-R9_8Lemo65lGpTLocbEKp4w_NRiG2UON__SbulKkGDDziEyXQwZ6A0g9TQn46qNSO6Q4_2T5_6kf7W1UE4dbFtHxeNaMPDUmMM4IwV4oItTmhQqymDzpL_Wnn2FDbhNXiLPk?expires=1727763300&#x26;signature=7ff07846060a623e9aa591179b703dee2d036f6049fc9194f9301b2e0ab3a64b&#x26;req=1tBtxFDyqnsp0xr0v9tnpOuBbc1qKwpYvuJ0ZX0Wg1tFP5%2BTm2iM6Ib6NFAU%0AuKNmqhR1twsxV1I%3D%0A" alt="" width="375"><figcaption></figcaption></figure>

3. &#x20;Click **Create StackSet.**\
   ![](https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2F05jVgDYpZLcztEIcWh02%2Fimage.png?alt=media\&token=8ecb74a4-a0f3-4ca1-af00-712509991a26)\
   The **Choose a template** step appears.<br>

   <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2FlPakTMUUclaAcxBOfEVt%2Fimage.png?alt=media&#x26;token=f1c80a04-fe07-4c5b-994c-c739a6da9012" alt=""><figcaption></figcaption></figure>
4. **Choose a template** - Fill in the following information:<br>
   1. **Permissions**: Since we are using the self-managed permissions, AWS manages the roles and you can skip this section.<br>

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2F4zRqySVeKyLWc4nB6Tdf%2Fimage.png?alt=media&#x26;token=656e0338-aec2-4fd7-afe6-0ab66b634aa4" alt=""><figcaption></figcaption></figure>
   2. **Prepare template** - Choose **Template is ready.**<br>

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2Fs817JOGoQDx1vmc6ukST%2Fimage.png?alt=media&#x26;token=9c654847-1672-4423-8d59-bfd3f44d204c" alt=""><figcaption></figcaption></figure>
   3. **Specify template** - Under the template source, choose Amazon S3 URL, and specify the following URL:\
      <https://finout-public-assets.s3.amazonaws.com/FinoutMetricsReadOnlyRole.json><br>

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2FGTRif2QzKdAd1mewgd6O%2Fimage.png?alt=media&#x26;token=98100bca-afd4-4008-a367-925aee0cefa6" alt=""><figcaption></figcaption></figure>
   4. Click **Next**.\
      You are brought to the **Specify stack set details** step.<br>

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2FQe2cNNo9i0OnPsqRrGIq%2Fimage.png?alt=media&#x26;token=72e89cd0-b75d-4166-8717-7b92ea889c8d" alt=""><figcaption></figcaption></figure>
5. **Specify stack set details** - Fill in the following information:
   1. **Stack set name** - Specify a name for the CloudFormation stack (e.g. finout-readonly-role).<br>

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2Fkbc5waTrheXypZ6l2yXY%2Fimage.png?alt=media&#x26;token=bf3d546b-5d21-4ac6-9bb5-52620b41cd50" alt=""><figcaption></figcaption></figure>
   2. **Parameters** - Add the External ID from the Finout-provided section.

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2FaB3fErEawy0cevTarueC%2Fimage.png?alt=media&#x26;token=14a0ecd9-bf42-4c9b-a6fe-ae061169aa1b" alt=""><figcaption></figcaption></figure>
   3. Click **Next**.\
      You are brought to the **Configure stack set options** step.
6. **Configure stack set options**:
   1. **Execution configuration**: Set Manage execution to **Active**.

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2Fyd7TKfQcyfgkYJxu7hZa%2Fimage.png?alt=media&#x26;token=4dbcf437-0f41-4ced-8dbd-34a695634a4e" alt=""><figcaption></figcaption></figure>
   2. Capabilities - Mark **I acknowledge the IAM** notice.

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2F0AI7udEYgvjFZ8PUBC3W%2Fimage.png?alt=media&#x26;token=7549be5a-b72a-49af-9f5c-4093ee57bdb8" alt=""><figcaption></figcaption></figure>
   3. Click **Next**.\
      You are brought to the **Set deployment options** step.<br>

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2FQDLmk4Dja1YFCJxudFUV%2Fimage.png?alt=media&#x26;token=fd2f91f0-5f1c-4a74-beb2-81180d44813e" alt=""><figcaption></figcaption></figure>
7. **Set deployment options**:
   1. **Add stacks to stack set** - Mark **Deploy new stacks**.

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2FjISL1wtWtWygagLSSIi0%2Fimage.png?alt=media&#x26;token=cca68ec3-f31d-4db7-beb3-6d2649cb5061" alt=""><figcaption></figcaption></figure>
   2. **Accounts** - You have two options:

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2FEYc4j12IXV48A0iH2vg6%2Fimage.png?alt=media&#x26;token=0a5a6f21-e1ba-41b1-800e-568729341588" alt=""><figcaption></figcaption></figure>

      * Mark **Deploy new stacks** in accounts for specifying which accounts to deploy the stack set.&#x20;
      * Mark **Deploy stacks in organizational units** to deploy all accounts. &#x20;
   3. **Specify Regions** - Choose **us-east-1**

      <figure><img src="https://3858159242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWqjB2puKXPDR7L86FX2e%2Fuploads%2Fuv345lmRyWStygwvY5nq%2Fimage.png?alt=media&#x26;token=17b1bb16-d502-4c0d-9ad0-2ea55434247f" alt=""><figcaption></figcaption></figure>
   4. **(Optional) Deployment options** - Configure the concurrency.
   5. Click **Next**.
8. Review all the information, then click **Next** to launch the new stack set.
9. Once the StackSets is complete, share your organization ID with Finout Support.

## Add Permissions Manually <a href="#h_a55a679675" id="h_a55a679675"></a>

Use the following JSON file to add permissions manually to your accounts:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "cloudwatch:ListMetrics",
        "cloudwatch:GetMetricData",
        "cloudwatch:GetMetricStatistics"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DescribeVolumes"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "organizations:ListAccounts",
      "Resource": "*"
    }
  ]
}
}
```

The latest IAM policy with details about each statement can be found below.

{% hint style="info" %}
**Note**: Finout applies a validation process on IAM policies applied per account, so please make sure to contact us before modifying the policy on your own.
{% endhint %}

### Finout IAM Policy Details <a href="#h_c4fb5814fe" id="h_c4fb5814fe"></a>

#### Cloudwatch Metrics <a href="#h_512aff2db8" id="h_512aff2db8"></a>

```json
{
  "Effect": "Allow",
  "Action": [
    "cloudwatch:ListMetrics",
    "cloudwatch:GetMetricData",
    "cloudwatch:GetMetricStatistics",
    "cloudwatch:Describe*"
  ],
  "Resource": "*"
},
```

This policy allows Finout read-only permission to Cloudwatch metrics - these are crucial for all recommendations provided by CostGuard (Idle and Rightsizing recommendations).

#### EBS Volumes <a href="#h_2fff04f936" id="h_2fff04f936"></a>

```json
{
  "Effect": "Allow",
  "Action": [
    "ec2:DescribeVolumes"
  ],
  "Resource": "*"
},
```

This section of the policy allows CostGuard to provide recommendations for unattached EBS volumes.

#### Organization Discovery <a href="#h_540327622b" id="h_540327622b"></a>

```json
{
  "Effect": "Allow",
  "Action": "organizations:ListAccounts",
  "Resource": "*"
} 
```

This section allows CostGuard to provide recommendations on all your accounts in the organization.
