Skip to content

This solution analyzes all of your Amazon WorkSpaces usage data and automatically converts the WorkSpace to the most cost-effective billing option (hourly or monthly), depending on your individual usage. Use this with a single account, or with AWS Organizations across multiple accounts, to help you monitor your WorkSpace usage and optimize costs.

License

Notifications You must be signed in to change notification settings

sanjay-reddy-kandi/cost-optimizer-for-amazon-workspaces

 
 

🚀 Solution Landing Page* | 🚧 Feature request | 🐛 Bug Report

Note: If you want to use the solution without building from source, navigate to Solution Landing Page.

Table of contents

Solution Overview

Amazon WorkSpaces, a fully managed, secure virtual desktop computing service on the AWS Cloud, eliminates the need for customers to procure, deploy, and manage complex virtual desktop environments. Amazon WorkSpaces offers the flexibility to pay hourly or monthly without any up-front commitment.

To help customers with unpredictable WorkSpace usage patterns monitor their Amazon WorkSpaces usage and optimize costs, AWS offers the Amazon WorkSpaces Cost Optimizer, a solution that analyzes all of your WorkSpace usage data and automatically converts the WorkSpace to the most cost-effective billing option (hourly or monthly) depending on the user's individual usage. This solution is easy to deploy and gives a choice to use either AWS Cloudformation or AWS CDKv2 to automatically provision and configure the necessary AWS services.

Architecture Diagram

alt Architecture Diagram

Getting Started

For deployment flexability and backwards compatability, there are two ways of deploying this solution: via Cloudformation and via CDK. The simplest way to get started is via AWS Cloudformation's WebUI. The programatic way via CDK allows customization of input parameters. Feel free to choose either ways of deployment to fit your needs.

Deploy via the CloudFormation Template for WorkSpaces Cost Optimizer

Deploy via CDKv2 with npm:

Preconfigure aws profile

git clone [email protected]:aws-solutions/cost-optimizer-for-amazon-workspaces.git


cd source

npm install

# set your preconfigured aws profile in ~/.aws/credentials
export AWS_PROFILE=""
export DIST_OUTPUT_BUCKET=solutions

npm run bootstrap -- --profile ${AWS_PROFILE}

npm run deploy -- --profile ${AWS_PROFILE} --parameters CreateNewVPC=Yes

For the full solution overview visit WorkSpaces Cost Optimizer on AWS

Customizing the Solution

Build

Clone the repository

git clone [email protected]:aws-solutions/cost-optimizer-for-amazon-workspaces.git

Create a distribution S3 bucket with the format MY-BUCKET-<aws_region>. The solution's cdk will expect the source code to be located in this bucket. <aws_region> is where you are testing the customized solution.

Note: When you create a bucket, a randomized value unique to your environment is recommended for the bucket name. As a best practice, enable the server side encryption and also block public access to the bucket.

export TEMPLATE_OUTPUT_BUCKET=<YOUR_TEMPLATE_BUCKET_NAME>
export DIST_OUTPUT_BUCKET=<YOUR_DIST_BUCKET_NAME>
export SOLUTION_NAME="cost-optimizer-for-amazon-workspaces"
export VERSION=<VERSION>
## NOTE THAT the region is appended to the DIST_BUCKET_NAME (DIST_BUCKET_NAME-REGION) when deployed, so creating a bucket with only Bucket_Name will not work.

Change the working directory to the deployment folder.

cd deployment

Run the build script.

chmod +x ./build-s3-dist.sh && ./build-s3-dist.sh $TEMPLATE_OUTPUT_BUCKET $DIST_OUTPUT_BUCKET $SOLUTION_NAME $VERSION

Upload the artifacts.

aws s3 cp ./dist/ s3://$BUCKET_NAME-[region]/cost-optimizer-for-amazon-workspaces/$VERSION --recursive

You should now have everything in place to run cdk or CloudFormation template(either from your bucket or from ./deployment/dist/).

Unit Test

chmod +x "./run-unit-tests.sh" && "./run-unit-tests.sh"

Deploy

Two methods of deploying: CDK or CloudFormation Template

  1. CDK: Run as seen in getting started section and then deploy spoke in a separate aws account
AWS_PROFILE=""
AWS_PROFILE_SPOKE=""

# Note: running bootstrap is only required once, not needed for every subsequent deployment.
npm run bootstrap -- --profile ${AWS_PROFILE}

npm run deploy -- --profile ${AWS_PROFILE} --parameters CreateNewVPC=Yes

HUB_ACCOUNT_ID=$(aws sts get-caller-identity --profile $AWS_PROFILE_SPOKE --query Account --output text)

npm run bootstrap -- --profile ${AWS_PROFILE_SPOKE} --parameter HubAccountId=$HUB_ACCOUNT_ID

npm run deploySpoke -- --profile ${AWS_PROFILE_SPOKE} --parameters HubAccountId=${HUB_ACCOUNT_ID}

  1. Cloudformation: For backwards compatibility, generate CloudFormation templates into source/cdk.out/ directory. Get the link of the cost-optimizer-for-amazon-workspaces.template loaded to your Amazon S3 bucket. Deploy the Workspaces Cost Optimizer solution to your account by launching a new AWS CloudFormation stack using the link of the cost-optimizer-for-amazon-workspaces.template. :
npm run synth

#  source/cdk.out/{cost-optimizer-for-amazon-workspaces.template.json, cost-optimizer-for-amazon-workspaces-spoke.template.json}

File structure

├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.txt
├── NOTICE.txt
├── README.md
├── SECURITY.md
├── buildspec.yml
├── deployment
│   ├── build-open-source-dist.sh
│   ├── build-s3-dist.sh
│   ├── run-unit-tests.sh
│   └── upload-s3-dist.sh
└── source
    ├── Dockerfile
    ├── bin
    │   └── cost-optimizer-for-amazon-workspaces-solution.ts
    ├── cdk.json
    ├── lambda
    │   ├── account_registration_provider
    │   │   ├── __init__.py
    │   │   ├── __tests__
    │   │   │   ├── __init__.py
    │   │   │   ├── conftest.py
    │   │   │   └── test_account_registration_provider.py
    │   │   └── account_registration_provider.py
    │   ├── register_spoke_lambda
    │   │   ├── __init__.py
    │   │   ├── __tests__
    │   │   │   ├── __init__.py
    │   │   │   ├── conftest.py
    │   │   │   ├── test_dynamodb.py
    │   │   │   ├── test_register_spoke_accounts.py
    │   │   │   └── test_request_event.py
    │   │   ├── dynamodb_table.py
    │   │   ├── register_spoke_accounts.py
    │   │   └── request_event.py
    │   ├── utils
    │   │   ├── __tests__
    │   │   │   ├── __init__.py
    │   │   │   ├── conftest.py
    │   │   │   └── test_cfnresponse.py
    │   │   └── cfnresponse.py
    │   └── uuid_helper
    │       ├── __init__.py
    │       ├── __tests__
    │       │   ├── __init__.py
    │       │   ├── conftest.py
    │       │   └── test_uuid_helper.py
    │       └── uuid_helper.py
    ├── lib
    │   ├── cdk-helper
    │   │   ├── add-cfn-nag-suppression.ts
    │   │   ├── condition-aspect.ts
    │   │   ├── override-logical-id.ts
    │   │   └── set-condition.ts
    │   ├── components
    │   │   ├── app-registry-hub-resources.ts
    │   │   ├── app-registry-spoke-resources.ts
    │   │   ├── ecs-cluster-resources.ts
    │   │   ├── register-spoke-account-resources.ts
    │   │   ├── solution-helper-resources.ts
    │   │   ├── usage-report-bucket-resources.ts
    │   │   └── vpc-resources.ts
    │   ├── cost-optimizer-for-amazon-workspaces-hub-stack.ts
    │   └── cost-optimizer-for-amazon-workspaces-spoke-stack.ts
    ├── package.json
    ├── package-lock.json
    ├── poetry.lock
    ├── pyproject.toml
    ├── tsconfig.json
    └── workspaces_app
        ├── main.py
        ├── test_workspaces_app.py
        └── workspaces_app
            ├── __init__.py
            ├── __tests__
            │   ├── __init__.py
            │   ├── conftest.py
            │   ├── test_account_registry.py
            │   ├── test_directory_reader.py
            │   ├── test_metrics_helper.py
            │   └── test_workspaces_helper.py
            ├── account_registry.py
            ├── directory_reader.py
            ├── metrics_helper.py
            ├── utils
            │   ├── __init__.py
            │   ├── __tests__
            │   │   ├── __init__.py
            │   │   ├── conftest.py
            │   │   ├── test_s3_utils.py
            │   │   └── test_timer.py
            │   ├── decimal_encoder.py
            │   ├── s3_utils.py
            │   ├── solution_metrics.py
            │   └── timer.py
            └── workspaces_helper.py

################################################

Collection of operational metrics

This solution collects anonymized operational metrics to help AWS improve the quality of features of the solution. For more information, including how to disable this capability, please see the Implementation Guide

License

See license here.

About

This solution analyzes all of your Amazon WorkSpaces usage data and automatically converts the WorkSpace to the most cost-effective billing option (hourly or monthly), depending on your individual usage. Use this with a single account, or with AWS Organizations across multiple accounts, to help you monitor your WorkSpace usage and optimize costs.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 73.2%
  • TypeScript 24.5%
  • Shell 2.2%
  • Dockerfile 0.1%