π Solution Landing Page* | π§ Feature request | π Bug Report
Note: If you want to use the solution without building from source, navigate to Solution Landing Page.
- Solution Overview
- Architecture Diagram
- Getting Started
- Customizing the Solution
- File Structure
- Collection of operational metrics
- License
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.
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
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
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/
).
chmod +x "./run-unit-tests.sh" && "./run-unit-tests.sh"
Two methods of deploying: CDK or CloudFormation Template
- 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}
- 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}
βββ 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
################################################
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
See license here.