Desktop and Application Streaming
Deploy the Cost Optimizer for Amazon WorkSpaces in a highly-regulated environment.
The Cost Optimizer for Amazon WorkSpaces is a tool that analyzes your Amazon WorkSpaces usage data and automatically converts the WorkSpace to the most cost-effective billing option depending on the individual usage. You can use the Cost Optimizer with a single account or with AWS Organizations across multiple accounts.
Customers in highly-regulated environments often have limited or nopublic internet access from their AWS infrastructure. These restrictions have posed challenges for implementing the Cost Optimizer. With the release of version 2.7 of the Cost Optimizer for Amazon WorkSpaces, customers have the option to implement the solution with an Amazon Elastic Container Registry (ECR) image in their own private repository and Amazon VPC endpoints, eliminating the need for public internet access.
In this blog we will walk through the configuration of the Cost Optimizer with private ECR images and Amazon VPC Endpoint configurations to eliminate the need for public internet access.
Prerequisites
- An AWS Account with necessary AWS Identity and Access Management (IAM) permissions to perform the tasks listed.
- An active Amazon WorkSpaces Personal deployment.
- Cost Optimizer for Amazon WorkSpaces 2.7 or later deployed into a separate VPC from your WorkSpaces VPC.
- Inter-VPC pairing either with Transit Gateway Attachments or VPC Peering between the Cost Optimizer VPC and the VPC(s) hosting your Amazon WorkSpaces.
- If you are deploying the Cost Optimizer in a Hub and Spoke design, the spoke VPCs will also need to be paired with the Hub VPC by either Transit Gateway Attachment or VPC Peering.
- Docker Desktop and Docker CLI installed on a physical computer.
Create private ECR repository
- Open the Amazon Elastic Container Registry console.
- On the left menu, choose Repositories then select Create repository.
- Provide a namespace and repository name and select Create.
- Note the Repository URI as you will need it for the next section.
Copy the Image
The Amazon ECR Public Gallery contains the official Docker image for the Cost Optimizer. Follow the guide for Pulling an image to your local environment from an Amazon ECR private repository and Pushing a Docker image to an Amazon ECR private repository
Create VPC Endpoints
- Open the Amazon VPC console. On the left menu, choose Endpoints.
- Select Create endpoint.
- In the Service category section select AWS services.
- Select com.amazonaws.<region>.sts in the services selection field. Where
<region>
is the region where your Cost Optimizer is deployed. - For VPC, select your Cost Optimizer VPC.
- Under Subnets, select both private subnets in your Cost Optimizer VPC.
- Under Security groups select the cost optimizer IntraVPCSecurityGroup that was created when you deployed the Cost Optimizer using the CloudFormation script. The name will be similar to
<stack_name>-IntraVPCSecurityGroup-<hash>
where<stack_name>
is the name of your CloudFormation stack. - Select Create endpoint.
- Repeat steps 1-8 to create the following interface endpoints.
- com.amazonaws.us-east-1.ecr.api
- com.amazonaws.us-east-1.ecr-dkr
- com.amazonaws.us-east-1.ecs-agent
- com.amazonaws.us-east-1.secretsmanager
- com.amazonaws.us-east-1.ecs-telemetry
- com.amazonaws.us-east-1.logs
- com.amazonaws.us-east-1.monitoring
- com.amazonaws.us-east-1.workspaces
If you have deployed the Cost Optimizer in a single region (no hub & spoke design) you will need to create a DynamoDB gateway endpoint as well.
- Open the Amazon mVPC console. From the left menu, choose Endpoints.
- Select Create endpoint.
- In the Service category section select AWS services.
- Select com.amazonaws.<region>.dynamodb where <region> is the region where your Cost Optimizer is deployed. Make sure you select the Gateway endpoint type.
- For VPC, select your Cost Optimizer VPC.
- Under Route Tables, select the route table with. your 2 private subnets associated.
- Select Create endpoint.
Update IAM Policies
Since you are using a private ECR image, your gateway endpoint and IAM role must have permissions to access the repository as well as the starport layer bucket; an S3 bucket containing the layers for each Docker image. Additionally, you will need to add some policy statements for the IAM role that is assumed when the task is run.
S3 endpoint policy
- From the VPC Console select Endpoints from the left menu. Select the S3 gateway endpoint.
- Select the Policy tab and select Edit Policy. Add the following policy statement to the existing statement block and select Save. Replace
<region>
in the Resource block to the Region where you are deploying.
{
"Sid": "Access-to-starport-layer-bucket",
"Principal": {
"AWS": "*"
},
"Action": [ "s3:GetObject" ],
"Effect": "Allow",
"Resource":[
"arn:aws:s3:::prod-<region>-starport-layer-bucket/*"
]
}
IAM policy
- From the IAM console select Roles from the left menu.
- Find the IAM role created with the cost optimizer deployment. The naming pattern will be
Workspaces-Cost-Optimizer-<region>
where<region>
is the AWS Region where the solution was deployed. - Select the role. Under the Permission tab select the CostOptimizerAdminPolicy. Add the following statements to the policy and select Next, followed by Save.
Replace <region>
with your AWS region in the below statement.
{
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:DescribeRepositories",
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage",
"ecr:GetLifecyclePolicy",
"ecr:GetLifecyclePolicyPreview",
"ecr:ListTagsForResource",
"ecr:DescribeImageScanFindings"
],
"Resource": ["*"]
},
{
"Effect": "Allow"
"Action": [
"s3:GetObject"
],
"Resource": ["arn:aws:s3:::prod-<region>-starport-layer-bucket/*"],
}
Security Group
- Open the VPC console. From the left menu, choose Security Groups.
- Find the security group that was created with the deployment of the Cost Optimizer and select that. The name will look similar to
<stack_name>-IntraVPCSecurityGroup-<hash>
where the<stack_name>
is the name of your CloudFormation stack that was created when you deployed the Cost Optimizer. - Select the Inbound rules tab and select Edit Inbound rules.
- Add the following inbound rules then click Save.
Type | Source | CIDR |
---|---|---|
DNS (UDP) | Custom | CIDR of your Cost Optimizer VPC |
DNS (TCP) | Custom | CIDR of your Cost optimizer VPC |
HTTPS | Custom | CIDR of your Cost Optimizer VPC |
Update the ECS Task
- Open the Amazon ECS console. From the left menu, choose Task definitions, then select the wco-task.
- Select the checkbox for latest task definition and select Create new revision.
- Scroll to the Container-1 section. In the Image URI field, paste the URI to your private ECR image.
- In the Environment variables – optional field, make the following changes/additions then select Create.
Type | Key | Old Value | New Value |
---|---|---|---|
Change | SendAnonymousData | True | False |
Add | AWS_STS_REGIONAL_ENDPOINTS | regional |
Update the EventBridge Rule
- Open the Amazon EventBridge console. From the left menu, choose Rules .
- Find the rule that was created when the Cost Optimizer was deployed. It will follow a format like
<stack_name>-ScheduleRule-<hash>
where<stack_name>
is the name of your CloudFormation stack that was created when you deployed the Cost Optimizer. - Select the rule. In the Targets tab select Edit.
- In the Task definition field, select the Revision radio button and select the latest revision you created in the last section.
- Select Next, Next then Update rule.
When your scheduled task runs, it will now use the latest revision of the task which is pointing to your private repository.
Testing
Manually run the ECS task to test the functionality of the new design.
- From the ECS console, select Task definitions from the left menu.
- Select the wco-task and select the check box next to the latest revision.
- Select Deploy → Run Task.
- Expand the Networking section. Select the Cost Optimizer VPC and select the 2 private subnets.
- Under Security group name select the
<stack_name>-IntraVPCSecurityGroup-<hash>
group where<stack_name>
is the name of your CloudFormation stack. - Set the Public IP option to Turned off.
- Select Create.
Your task will now execute. This will take a few minutes to complete. When completed you can see the results in the S3 bucket created when the solution was deployed.
Cleanup
To avoid unwanted AWS charges, you must remove the infrastructure created in this blog:
- Delete the VPC endpoints.
- Open the Amazon VPC console. On the left menu, choose Endpoints.
- Select the checkbox next to each endpoint you created in this blog.
- Select Actions then Delete Endpoints.
- Type delete into the confirmation field and select Delete.
- Deregister the ECS task revision.
- Open the Elastic Container Service console. From the left menu, select Task definitions.
- Select the wco-task definition.
- Select the checkbox next to the task revision you created in this blog.
- Select Actions, then Deregister.
- Delete the ECR image and repository.
At this point, you have deleted all resources created in this blog. If you would also like to remove the Cost Optimizer for Amazon WorkSpaces that was defined as a prerequisite, continue with steps 4-6.
- Delete the CloudFormation template you created to deploy the Cost Optimizer.
- Delete the S3 bucket and contents that was deployed in the CloudFormation Script.
- Delete the CloudWatch log groups that was deployed in the CloudFormation Script.
Conclusion
In this blog you modified the Cost Optimizer for Amazon WorkSpaces to run in an environment without internet connectivity by utilizing a private ECR image and VPC endpoints. To see a video of this solution check out our YouTube video and our YouTube playlist for other EUC videos.
Robert Fountain is a Sr. EUC Specialist Solutions Architect based out of Pennsylvania. Robert has been with AWS since 2020 and currently holds six AWS Certifications. Outside of the office, Robert is a member of the National Ski Patrol and enjoys spending time with his wife, 2 boys, and his dog, Daisy. | |
Dave Jaskie brings 15 years of experience in the End User Computing space. Outside of Work, Dave enjoys traveling and hiking with his wife and 4 kids. |