Code Monkey home page Code Monkey logo

whodoneitagain / cost-optimizer-for-amazon-workspaces Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aws-solutions/cost-optimizer-for-amazon-workspaces

0.0 0.0 0.0 908 KB

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.

Home Page: https://aws.amazon.com/solutions/implementations/cost-optimizer-for-amazon-workspaces/

License: Other

Shell 3.08% Python 67.37% TypeScript 29.47% Dockerfile 0.07%

cost-optimizer-for-amazon-workspaces's Introduction

๐Ÿš€ 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
โ”œโ”€โ”€ 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 anonymous 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.

cost-optimizer-for-amazon-workspaces's People

Contributors

aijunpeng avatar deolank avatar georgebearden avatar groverlalit avatar gsingh04 avatar hayesry avatar hnishar avatar hortontp avatar hyandell avatar shsenior avatar stevemorad avatar willaws avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.