Desktop and Application Streaming
Automate copy of Amazon WorkSpaces tags to hybrid activation resources in AWS Systems Manager
AWS Systems Manager allows customers to manager their Amazon WorkSpaces using hybrid activation managed nodes. Systems Manager provides software inventories, OS patches, and configuration of Windows and Linux WorkSpaces, but it is difficult to identify and map managed node to the corresponding WorkSpaces without any tags. This is a time-consuming process in large organizations where IT Admins manually create these tags for each managed node in Systems Manager. This additional repetitive task leads to inconsistencies and wasted administrative time. The inconsistency in Systems Manager tags can lead to operational errors and other issues.
This blog describes how to implement an automation to copy tags from Amazon WorkSpaces to their corresponding managed node in Systems Manager, deployed using an AWS CloudFormation template.
Time to read | 15 minutes |
Time to complete | 5 minutes |
Learning level | Expert(400) |
Cost to complete (estimated) | $5 (can vary with interval rate) |
Services used | Amazon WorkSpaces AWS Systems Manager AWS CloudFormation AWS Lambda Amazon EventBridge |
Overview of solution
In this solution, we will demonstrate how you can reduce operational burden of manually creating tags for the WorkSpaces managed nodes. To implement this solution, you will use AWS CloudFormation to automatically configure all the required AWS services.
This solution uses Amazon EventBridge to invoke an AWS Lambda function on specified interval. The Lambda function then collects the WorkSpaces and managed nodes in Systems Manager. The Lambda Function matches both resources using the computer name, and then copies the tags of each WorkSpace to its matched managed node. In addition, the Lambda function creates the following tags for identification: Name, WorkspaceID, UserID, BundleID, DirectoryID, DirectoryName, and RegistrationCode.
Walkthrough
In this article, you will perform following activities:
- Use CloudFormation to deploy the solution to automatically copy WorkSpaces tags to their managed node in Systems Manager.
- Cleanup resources to prevent unwanted AWS usage charges.
Prerequisites
For this walkthrough, you need the following:
- An AWS account.
- An Amazon WorkSpaces deployment
- An AWS Systems Manager hybrid activation deployment.
- Permissions to create following service components:
- AWS Identity and Access Management (IAM) roles and policies
- AWS Lambda functions
- Amazon EventBridge rule
- Permissions to run AWS CloudFormation templates.
- Basic familiarity with AWS CloudFormation, AWS Systems Manager, Amazon WorkSpaces, and Amazon EventBridge.
Step 1: Deployment of solution via AWS CloudFormation
You will use the provided CloudFormation template to deploy and configure all the required AWS services of this solution. This template cannot be used for WorkSpaces and managed nodes in different accounts or AWS Regions. This deployment is Region specific, and must run in the AWS Region that contains your Amazon WorkSpaces and hybrid activated managed nodes.
Use the following steps to deploy the solution via AWS CloudFormation:
- Open a text editor on your local machine.
- Copy the below CloudFormation template to your text editor.
- Save notepad file with YAML file extension.(<filename>.yaml).
- Open the AWS CloudFormation console.
- Select the AWS Region of your WorkSpaces deployment.
- In the navigation pane, choose Stacks.
- Choose Create stack, then choose With new resources (standard).
- On the Create stack page, select Upload a Template File.
- Select Choose File, choose template file that you saved in step 3.
- Choose Next.
- In the Stack name section, enter a stack name.
- In the Parameters section, enter the following values:
- For EventBridgeRuleName, enter a unique name for the EventBridge rule.
- For IAMRoleName, enter a unique name for the IAM Role.
- For IntervalRate, enter an interval rate in the Rate Expression format. Amazon EventBridge will run this automation at interval rate specified.
- For LambdaFunctionName, enter a unique name for the Lambda function.
- Choose Next
- On the Configure stack options page, leave all the defaults, and choose Next.
- Review the configuration options and acknowledge the IAM checkbox.
- Choose Submit.
- Verify that the stack has a status of CREATE_COMPLETE.
The stack deploys in approximately 2 minutes and creates the following resources:
- AWS Lambda function
- Amazon EventBridge Rule
- IAM Role
Step 2: Validate the creation of new Tags for hybrid activated managed node in AWS Systems Manager.
You now have an Amazon EventBridge Rule and AWS Lambda function configured. Tags are created for the managed nodes after the interval specified during the creation of the AWS CloudFormation Stack. Use the following steps to validate the tags in Systems Manager:
- Open the AWS Systems Manager console.
- Select the AWS Region of your managed nodes.
- In the navigation pane, choose Fleet Manager from Node Management.
- Select any of the Managed Nodes created for WorkSpaces.
- Verify the created tags in Tags section.
Cleaning up
It is important to clean up unused resource to avoid unexpected usage fees. To clean up the environment, delete AWS CloudFormation stacks you created in the walkthrough. Deletion of AWS CloudFormation will delete Lambda function, EventBridge rules and associated IAM roles. You must manually delete the tags created for managed nodes in Systems Manager via console or API.
Conclusion
In this blog, you configured Amazon EventBridge with AWS Lambda functions to automatically copy AWS WorkSpace’s tags to their corresponding Systems Manager managed nodes.
To learn more about Amazon WorkSpaces, please review the administration guide. You can get more information about hybrid activation in AWS Systems Manager using this link.
If you would like to discuss how to configure this solution described in this blog for your specific use case, we would love to hear from you. Please reach out to your account team.
-
Ajay Saini is a End User Compute Specialist Solution Architect. He works with his customer to help them understand the best practices, accelerate their architecture design, migrate and modernize their existing Virtual Desktop Infrastructure (VDI) to AWS. In his spare time, he enjoys travel and spending time with his family Brandon Mahtani is an EUC Specialist Solutions Architect who joined AWS in December of 2018 with over 20 years experience deploying desktop virtualization solutions within Higher Education as well as the Life Sciences industries.