AWS Data Collection Using a CloudFormation Template
Overview
Kubex’s CloudFormation template creates a comprised of the AWS resources required by Kubex to collect the Resource Utilization Metrics (via CloudWatch) that are then used for cloud optimization analysis. If your accounts are setup using an AWS organization/management account structure, in which many accounts are linked to one management account, you can use the CloudFormation template to create, update and delete StackSets across multiple accounts and also create the cloud connection within Kubex for each of the linked accounts. If you are not using an organizational account structure you can provide a list of accounts to be updated when you are configuring the stack.Figure: Onboarding AWS Accounts Using CloudFormation
Figure: Onboarding AWS Accounts Using CloudFormation

Supported Regions
You can run the Kubex CloudFormation template in any of the following regions;
|
|
|
Additional Considerations Regarding Regions
When you create the StackSet, you need to specify a region from where the stack is deployed to each account and from where the Lambda function runs. Ensure you specify a single region as the IAM role and permission policy are globally accessible and as such will work from any region. If you try to re-run the template in a different region it will fail as the IAM role and the permission policy already exist. The Lambda function is region-specific and creates the cloud connections within Kubex during deployment. CloudFormation can also invoke it when its custom resources are updated or deleted. The StackSet and the CloudWatch logs that result from running the template are also region-specific and are defined within a specific region. You need to log into the specified region to manage your Stack and view its related log files. These log files will be required by the Kubex support team, if troubleshooting any data collection issues.Using the CloudFormation Template
If your AWS accounts are setup using an organizational structure, in which many accounts are linked to one management account, you can use the CloudFormation template to create, update and delete stacks across multiple accounts and also create the cloud connection within Kubex for each of the linked accounts. If you are using this organizational structure, your AWS sign-in must have sufficient permissions to deploy the StackSet and create the required IAM roles and policies in the linked accounts. If you are not using an organizational account, you can provide a list of accounts in which the CloudFormation template will run and create the required prerequisites for data collection. In addition to creating connections from your linked accounts, you also need to create a connection for your payer accounts. The payer account connection provides the name of each linked accounts.Prerequisites
Obtain the following required inputs for the template before starting:- External ID for IAM Role—This value is similar to a password and should be unique and difficult to guess. Kubex recommends using a password generator to create a random, alphanumeric string (e.g. ae73mcf4ldjpet96) for the external ID.
- Both the URL and user credentials for your Kubex instance—Contact your Kubex Account Manager for details if you do not have this information.
- AWS permissions—If you are using an AWS Organization with multiple linked accounts, your AWS sign-in must have sufficient permissions to deploy the StackSet and create the required IAM roles and policies in those accounts.
Considerations when Working with Large Environments
In large environments, Kubex highly recommends batching your accounts into smaller groups for improved performance when using the CloudFormation templates. i.e. no more than 10 accounts at a time. You can use a resource tag, such as application or business unit to separate the CloudFormation stack so that data is collected in manageable batches.Configuring and Running the Template
Step 1: Choose a Template
- Log into the AWS Management Console and navigate to CloudFormation and select StackSets. You may need to expand the options in the upper left corner of the page:
Figure: Accessing Stack Options
Figure: Accessing Stack Options

- At the top of the StackSets page, select a supported region. See the list of Supported Regions.
- Click Create StackSet to begin.
Figure: Create StackSet Options
Figure: Create StackSet Options

- In the Permissions section at the top of the page select the applicable option.
- Service-managed permissions—Use this option when you want the AWS Organization to automatically manage permissions. This is useful if you have a large number of accounts under an organization and you want to simplify the management of permissions across these accounts.
- Self-managed permissions—Use this option when you need more granular control over permissions or when you are working in an environment where accounts are not part of the same AWS organizational structure.
- If you selected “Self-managed permissions”, then specify an IAM role that has execute privileges in your target linked accounts.
Figure: Specify CloudFormation Permissions
Figure: Specify CloudFormation Permissions

- In the next section, Prerequisite - Prepare template, select Template is ready
-
In Specify template, paste the following URL into the Amazon S3 URL field:
https://kubex-cf-template.s3.us-east-2.amazonaws.com/Kubex_CloudFormation.ymlAlready using the Densify template? Continue using it. See Editing the StackSet for the latest template and update guidance. - Click Next to proceed with creating the stack.
Figure: Specify CloudFormation Template
Figure: Specify CloudFormation Template

Step 2: Specify StackSet Details
- Enter the following StackSet details:
- Stack name—Kubex-Data-Collection, as an example.
- Stack description—Optionally enter a description for this StackSet
Figure: Specify CloudFormation Template
Figure: Specify CloudFormation Template

- Enter the following Kubex instance details:
- Kubex Instance URL—This is your Kubex SaaS instance.
- Kubex User ID—This is your Kubex user name.
- Kubex Password—This is the password for the listed user name.
Figure: Specify Kubex Instance Details
Figure: Specify Kubex Instance Details

- Enter the External ID for IAM Role that you prepared in the prerequisites.
- The values for IAM Role Name and the Permission Policy Name fields are provided. You do not need to enter any values here.
- Click Next to proceed with creating the stack.
Step 3: Configure StackSet Options
- In the Configure StackSet options page, accept the default values and then click Next.
- Tags—No tags need to be specified for the StackSet.
- Inactive—Leave this value to simplify StackSet execution.
Step 4: Set Deployment Options
Set the following deployment options- In the first section, Add stacks to stack set select Deploy new stacks.
Figure: Specify Account Details
Figure: Specify Account Details

- Under Accounts > Deployment locations , define the accounts to which you want to deploy the StackSet:
- Deploy Stacks in accounts—Enter the 12-digit account numbers in the field.
- Deploy stacks in organizational units—Specify the organization units to use. The StackSet will be deployed to all account in the specified organizational units.
- In the next section, select one region from which the StackSet will be managed. This is typically the same region from which the StackSet is deployed. See the list of Supported Regions.
- Set the following Deployment Options:
- Maximum Concurrent Accounts—Choose Number from the dropdown list and enter a value of 10.
- Failure Tolerance (Optional)—Specify the maximum number or percentage of stack operation failures allowed per region. If this threshold is exceeded, CloudFormation stops the operation.
When using Strict failure tolerance with account counts, Maximum Concurrent Accounts cannot exceed Failure Tolerance + 1. For example, a concurrency setting of 10 requires a failure tolerance of at least 9.
- Region Concurrency—Select the desired option. As long as Maximum Concurrent Accounts is specified, parallel is preferred.
- Concurrency Mode—Leave the default value, of “Strict failure tolerance”.
Figure: Deployment Options
Figure: Deployment Options

- Click Next to proceed with creating the stack.
Step 5: Review
- Scroll through each section and verify the data you have entered.
- At the bottom of the page, in the Capabilities section, click the checkbox to acknowledge that the StackSet will create IAM resources with custom names, as required.
Figure: Permission to Create Resources
Figure: Permission to Create Resources

Step 6: Run the Template
- Click Submit to begin the process. The CloudFormation dashboard displays the stack creation progress.
- Open the StackSet’s Operations tab to monitor deployment progress and status.
-
After deployment succeeds, open the Stack instances tab and follow a stack ID link to view an individual stack:
- Open Events to review that stack’s deployment events.
- Open Resources to review the created resources.
- Open Outputs to review the template and Lambda version information.
- You can also log into your Kubex instance and verify that the cloud connections are listed in the Cloud Connection wizard.
Figure: Outputs Tab
Figure: Outputs Tab

Other StackSet Operations
To update an existing StackSet, choose Actions > Edit StackSet details and use the appropriate Kubex template update.Existing Densify deployments: Continue using the Densify template; switching to the Kubex template is not supported.
- Push changes to the existing stack in your accounts.
- Add the stack to additional accounts.
- Delete the stack from the accounts.
Editing the StackSet
In most cases you will only need to edit the set of minimum required permissions. The list of minimum required permissions changes as Kubex adds new features and functionality,- Log into the AWS Management Console and navigate to CloudFormation and select StackSets.
- Select the StackSet you want to edit and then choose Actions > Edit StackSet details from the dropdown menu at the top of the page.
Existing Densify deploymentsContinue using the latest Densify template. Switching to the Kubex template is not supported.See the Densify release manifest for current versions and release history.
Figure: Edit StackSet Details
Figure: Edit StackSet Details

Adding the StackSet to New Accounts
- Log into the AWS Management Console and navigate to CloudFormation and select StackSets.
- Select the StackSet you want to add and then choose Actions > Add new stacks to StackSet then specify the new accounts as outlined in Step 4.
When adding accounts, deploy the template currently associated with your StackSet.
Deleting a StackSet from Accounts
- Log into the AWS Management Console and navigate to CloudFormation and select StackSets.
- Select the StackSet you want to delete and then choose Actions > Delete stacks from StackSet then specify the accounts as outlined in Step 4.
- Navigate to Set Deployment Options and edit the list of accounts.
Figure: Specify Account Details
Figure: Specify Account Details

- Deleting the stacks also removes the associated cloud connections from Kubex.

