## 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}
```
2. 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](https://docs.aws.amazon.com/solutions/latest/cost-optimizer-for-workspaces/appendix.html)
# License
See license
[here](https://github.com/aws-solutions/cost-optimizer-for-amazon-workspaces/blob/main/LICENSE.txt).