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

aws-solutions/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
    β”œβ”€β”€ testing_requirements.txt
    β”œβ”€β”€ tsconfig.json
    └── workspaces_app
        β”œβ”€β”€ main.py
        β”œβ”€β”€ requirements.txt
        β”œβ”€β”€ setup_requirements.txt
        β”œβ”€β”€ 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.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published