

# Deploy the solution
<a name="deploy-the-solution"></a>

**Important**  
Don’t set the parameters **Simulate End of Month Cleanup** and **Terminate workspaces not used for a month** to `Yes` at the same time. Doing this will unexpectedly terminate WorkSpaces.  
The **Simulate End of Month Cleanup** parameter will run the solution as if it’s the last day of the month and then terminate WorkSpaces unexpectedly. To use the **Terminate unused WorkSpaces** feature, set **Simulate End of Month Cleanup** to `No`.

This solution uses AWS CloudFormation to automate the deployment of Cost Optimizer for Amazon WorkSpaces on the AWS Cloud. It includes the following AWS CloudFormation templates, which you can download before deployment.

This solution uses [CloudFormation templates and stacks](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-whatis-concepts.html) to automate its deployment. The CloudFormation templates describe the AWS resources included in this solution and their properties. The CloudFormation stack provisions the resources that are described in the templates.

## Deployment process overview
<a name="deployment-overview"></a>

Before you launch the automated deployment, please review the [cost](cost.md), [architecture](architecture.md), [network security](security.md), and other considerations discussed in this guide. Follow the step-by-step instructions in this section to configure and deploy the solution into your account.

**Note**  
Deploy the hub template first. If you have a single-account environment, you do not need to deploy the spoke template. If you have a multi-account environment, install the spoke template for each WorkSpaces account you wish to monitor.

 **Time to deploy:** Approximately five minutes

 [Step 1: Launch the hub stack](launch-the-stack-hub-template.md) 
+ Launch the AWS CloudFormation template in your hub account
+ Enter values for the required parameters
+ Review the other template parameters and adjust, if necessary

 [Step 2: Launch the spoke stack](launch-the-spoke-stack.md) 
+ Launch the CloudFormation template in your spoke account
+ Enter values for the required parameters
+ Review the other template parameters and adjust, if necessary

**Note**  
This solution includes data collection. We use this data to better understand how customers use this solution and related services and products. AWS owns the data gathered through this survey. Data collection is subject to the [AWS Privacy Policy](http://aws.amazon.com/privacy/).

# AWS CloudFormation templates
<a name="templates"></a>

You can download the CloudFormation templates for this solution before deploying it.

## Hub account
<a name="hub-account"></a>

 [https://solutions-reference.s3.amazonaws.com/cost-optimizer-for-amazon-workspaces/latest/cost-optimizer-for-amazon-workspaces.template](https://solutions-reference.s3.amazonaws.com/cost-optimizer-for-amazon-workspaces/latest/cost-optimizer-for-amazon-workspaces.template) 

 **cost-optimizer-for-amazon-workspaces.template** - Use this template to launch Cost Optimizer for Amazon WorkSpaces and all associated components for your hub account (or single account if you only have one account). The default configuration deploys AWS Lambda functions, an Amazon ECS task definition, an Amazon CloudWatch event, and an Amazon S3 bucket. You can customize the template based on your specific needs.

## Spoke accounts
<a name="spoke-accounts"></a>

 [https://solutions-reference.s3.amazonaws.com/cost-optimizer-for-amazon-workspaces/latest/cost-optimizer-for-amazon-workspaces-spoke.template](https://solutions-reference.s3.amazonaws.com/cost-optimizer-for-amazon-workspaces/latest/cost-optimizer-for-amazon-workspaces-spoke.template) 

 **cost-optimizer-for-amazon-workspaces-spoke.template** − Use this template to launch Cost Optimizer for Amazon WorkSpaces and all associated components for your spoke accounts. Do not deploy this template if you only have one account. The default configuration deploys AWS Lambda functions, an Amazon ECS task definition, an Amazon CloudWatch event, and an Amazon S3 bucket. You can customize the template based on your specific needs.

**Note**  
If you have previously deployed this solution, see [Update the solution](update-the-solution.md) for update instructions.

# Step 1: Launch the hub stack
<a name="launch-the-stack-hub-template"></a>

This automated AWS CloudFormation template deploys Cost Optimizer for Amazon WorkSpaces on the AWS Cloud.

1. Sign in to the [AWS Management Console](https://console.aws.amazon.com/console/) and select the button to launch the `cost-optimizer-for-amazon-workspaces` AWS CloudFormation template.

    [https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?templateURL=https:%2F%2Fsolutions-reference.s3.amazonaws.com%2Fcost-optimizer-for-amazon-workspaces%2Flatest%2Fcost-optimizer-for-amazon-workspaces.template&redirectId=ImplementationGuide](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?templateURL=https:%2F%2Fsolutions-reference.s3.amazonaws.com%2Fcost-optimizer-for-amazon-workspaces%2Flatest%2Fcost-optimizer-for-amazon-workspaces.template&redirectId=ImplementationGuide) 

1. The template launches in the US East (N. Virginia) Region by default. To launch Cost Optimizer for Amazon WorkSpaces in a different AWS Region, use the Region selector in the console navigation bar.
**Note**  
This solution can be launched as a single account deployment or multi account deployment. For single account deployment, you only need to deploy the hub template in the account you want to monitor the workspaces for. The multi account deployment works in the hub and spoke model.For multi account deployment, you need to deploy the hub template in a central account and provide AWS Organization ID and Management Account ID in the input parameters for the hub account.

1. On the **Create Stack** page, verify that the correct template URL is in the **Amazon S3 URL** text box and choose **Next**.

1. On the **Specify stack details** page, assign a name to your solution stack. For information about naming character limitations, see [IAM and AWS STS quotas, name requirements, and character limits](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html) in the *AWS Identity and Access Management User Guide*.

1. Under **Parameters**, review the parameters for the template and modify them as necessary. This solution uses the following default values.
**Important**  
Don’t set the parameters **Simulate End of Month Cleanup** and **Terminate workspaces not used for a month** to `Yes` at the same time. Doing this will lead to unexpected WorkSpace termination

The **Simulate End of Month Cleanup** parameter will run the solution as if it’s the last day of the month and then terminate WorkSpaces unexpectedly. To use the Terminate unused WorkSpaces feature, set **Simulate End of Month Cleanup** to `No`.


| Parameter | Default | Description | 
| --- | --- | --- | 
|   **Select New or Existing VPC for AWS Fargate**   |  |  | 
|   **Create New VPC**   |   `Yes`   |  Select `Yes` to deploy the solution in a new Amazon VPC.  | 
|   **Existing VPC Settings**   |  |  | 
|   **Public Subnet ID**   |   *<Optional input>*   |  A public subnet ID to launch the gateway. Leave this blank if you selected `Yes` for **Create New VPC** or enter an existing subnet ID to run an Amazon ECS task.  | 
|   **First Public Subnet ID**   |   *<Optional input>*   |  A Private Subnet ID to launch ECS task. Leave this blank if you `Yes` for **Create New VPC** .  | 
|   **Second private subnet ID for second subnet**   |   *<Optional input>*   |  A second private subnet ID to launch an Amazon ECS task. Leave this blank if you selected `Yes` for **Create New VPC** or enter an existing subnet ID to run an Amazon ECS task.  | 
|   **Security group ID to launch ECS task**   |   *<Optional input>*   |  Security group ID to launch an Amazon ECS task Leave this blank if you selected `Yes` for **Create New VPC** or enter an existing security group ID to run an Amazon ECS task.  | 
|   **New VPC Settings**   |  |  | 
|   **AWS Fargate VPC CIDR Block**   |   `10.215.0.0/16`   |  The default VPC CIDR used to deploy the AWS Fargate container dynamically when the solution runs.  | 
|   **Public Subnet CIDR Block**   |   `10.215.10.0/24`   |  A public subnet to which the internet gateway is deployed.  | 
|   **AWS Fargate Private Subnet1 CIDR Block**   |   `10.215.30.0/24`   |  One of two private subnets in different Availability Zones where the AWS Fargate container is deployed.  | 
|   **AWS Fargate Private Subnet2 CIDR Block**   |   `10.215.40.0/24`   |  The second of two subnets in different Availability Zones where the AWS Fargate container is deployed.  | 
|   **AWS Fargate SecurityGroup CIDR Block**   |   `0.0.0.0/0`   |  The CIDR block to restrict the Amazon ECS container outbound access.  | 
|   **Testing Parameters**   |  |  | 
|   **Launch in Dry Run Mode**   |   `Yes`   |  Generates a change log, but does not inact any changes. For more information, refer to [Dry Run Mode](features-and-benefits.md#dry-run-mode).  | 
|   **Simulate End of Month Cleanup**   |   `No`   |  Overrides date and forces the solution to run as if it is the end of the month.  | 
|   **Log Level**   |   `INFO`   |  Sets the log level for the Lambda function logs in CloudWatch.  | 
|   **Pricing Parameters**   |  |  | 
|   **ValueLimit**   |   `81`   |  The number of hours a Value instance can run in a month before being converted to `ALWAYS_ON`.  | 
|   **StandardLimit**   |   `85`   |  The number of hours a Standard instance can run in a month before being converted to `ALWAYS_ON`.  | 
|   **PerformanceLimit**   |   `83`   |  The number of hours a Performance instance can run in a month before being converted to `ALWAYS_ON`.  | 
|   **GraphicsG4dnLimit**   |   `217`   |  The number of hours a Graphics instance can run in a month before being converted to `ALWAYS_ON`.  | 
|   **GraphicsProG4dnLimit**   |   `80`   |  The number of hours a GraphicsPro instance can run in a month before being converted to `ALWAYS_ON`.  | 
|   **PowerLimit**   |   `83`   |  The number of hours a Power instance can run in a month before being converted to `ALWAYS_ON`.  | 
|   **PowerProLimit**   |   `80`   |  The number of hours a PowerPro instance can run in a month before being converted to `ALWAYS_ON`.  | 
|   **GeneralPurpose4xlargeLimit**   |   `121`   |  The number of hours a GeneralPurpose.4xlarge instance can run in a month before being converted to `ALWAYS_ON`.  | 
|   **GeneralPurpose8xlargeLimit**   |   `125`   |  The number of hours a GeneralPurpose.8xlarge instance can run in a month before being converted to `ALWAYS_ON`.  | 
|   **Container Image**   |  |  | 
|   **Auto-Update Container Image**   |   `Yes`   |  Automatically use the most up to date and secure image up until the next minor release. Selecting `No` will pull the image as originally released, without any security updates.  | 
|   **List of AWS Regions**   |  |  | 
|   **List of AWS Regions**   |   *<Requires input>*   |  Comma separated list of AWS Regions for the solution to monitor. Example: `us-east-1`, `us-west-2`.  | 
|   **Terminate unused workspaces**   |  |  | 
|   **Terminate workspaces not used for a month**   |   `No`   |  Select `Yes` to delete WorkSpaces not used for one month.  | 
|   **Number of months for termination check**   |   `1`   |  Provide the number of months to check for inactive period before termination. Default value is `1` month.  | 
|   **Multi account deployment**   |  |  | 
|   **Organization ID for multi account deployment**   |   *<Optional input>*   |  AWS Organizations ID to support multi-account deployment. Leave blank for single account deployments.  | 
|   **Account ID of the Management Account for the Organization**   |   *<Optional input>*   |  Account ID for the Organization’s management account. Leave blank for single account deployments.  | 

1. Choose **Next.** 

1. On the **Configure stack options** page, choose **Next**.

1. On the **Review and create** page, review and confirm the settings. Select the box acknowledging that the template will create IAM resources.

1. Choose **Submit** to deploy the stack.

You can view the status of the stack in the AWS CloudFormation console in the **Status** column. You should see a status of CREATE\$1COMPLETE in approximately five minutes.

**Note**  
In addition to the `CostOptimizerCreateTask` AWS Lambda function, this solution includes the `solution-helper` Lambda function, which runs only during initial configuration or when resources are updated or deleted.  
When running this solution, you will see all Lambda functions in the AWS Management Console, but only the `CostOptimizerCreateTask` function is regularly active. However, do not delete the `solution-helper` function as it is necessary to manage associated resources.

# Step 2: Launch the spoke stack
<a name="launch-the-spoke-stack"></a>

This automated CloudFormation template deploys the spoke for Cost Optimizer for Amazon WorkSpaces on the AWS Cloud.

1. Sign in to the [AWS Management Console](https://console.aws.amazon.com/console/) and select the button to launch the `cost-optimizer-for-amazon-workspaces-spoke` AWS CloudFormation template.

    [https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?templateURL=https:%2F%2Fsolutions-reference.s3.amazonaws.com%2Fcost-optimizer-for-amazon-workspaces%2Flatest%2Fcost-optimizer-for-amazon-workspaces-spoke.template&redirectId=ImplementationGuide](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?templateURL=https:%2F%2Fsolutions-reference.s3.amazonaws.com%2Fcost-optimizer-for-amazon-workspaces%2Flatest%2Fcost-optimizer-for-amazon-workspaces-spoke.template&redirectId=ImplementationGuide) 

1. The template launches in the US East (N. Virginia) Region by default. To launch Cost Optimizer for Amazon WorkSpaces in a different AWS Region, use the Region selector in the console navigation bar.
**Note**  
The spoke account template should be deployed in any account you want to monitor with from the hub account deployment. Once deployed, the spoke template will register this account with the hub account deployment. The ECS task in the hub account will now monitor the WorkSpaces in the spoke account. You do not need to deploy the spoke account in the hub account to monitor the WorkSpaces in the hub account.

1. On the **Create Stack** page, verify that the correct template URL is in the **Amazon S3 URL** text box and choose **Next**.

1. On the **Specify stack details** page, assign a name to your solution stack. For information about naming character limitations, see [IAM and AWS STS quotas, name requirements, and character limits](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html) in the *AWS Identity and Access Management User Guide*.

1. Under **Parameters**, review the parameters for the template and modify them as necessary. This solution uses the following default values.    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/solutions/latest/cost-optimizer-for-workspaces/launch-the-spoke-stack.html)

1. Choose **Next.** 

1. On the **Configure stack options** page, choose **Next**.

1. On the **Review and create** page, review and confirm the settings. Select the box acknowledging that the template will create IAM resources.

1. Choose **Submit** to deploy the stack.

You can can view the status of the stack in the CloudFormation console in the Status column. You should receive a `CREATE_COMPLETE` status in approximately five minutes

**Note**  
In addition to the **CostOptimizerCreateTask** AWS Lambda function, this solution includes the solution-helper Lambda function, which runs only during initial configuration or when resources are updated or deleted.

When running this solution, you will see all Lambda functions in the AWS Management Console, but only the `CostOptimizerCreateTask` function is regularly active. However, don’t delete the `solution-helper` function because it’s necessary to manage associated resources.