Set up UiPath RPA bots automatically on Amazon EC2 by using AWS CloudFormation - AWS Prescriptive Guidance

Set up UiPath RPA bots automatically on Amazon EC2 by using AWS CloudFormation

Created by Dr. Rahul Sharad Gaikwad (AWS) and Tamilselvan P (AWS)

Environment: PoC or pilot

Technologies: Infrastructure; DevOps

Workload: All other workloads

AWS services: Amazon CloudWatch; EC2 Image Builder; AWS Systems Manager; AWS CloudFormation

Summary

This pattern explains how you can deploy robotic process automation (RPA) bots on Amazon Elastic Compute Cloud (Amazon EC2) instances. It uses an EC2 Image Builder pipeline to create a custom Amazon Machine Image (AMI). An AMI is a preconfigured virtual machine (VM) image that contains the operating system (OS) and preinstalled software to deploy EC2 instances. This pattern uses AWS CloudFormation templates to install UiPath Studio Community edition on the custom AMI. UiPath is an RPA tool that helps you set up robots to automate your tasks.

As part of this solution, EC2 Windows instances are launched by using the base AMI, and the UiPath Studio application is installed on the instances. The pattern uses the Microsoft System Preparation (Sysprep) tool to duplicate the customized Windows installation. After that, it removes the host information and creates a final AMI from the instance. You can then launch the instances on demand by using the final AMI with your own naming conventions and monitoring setup.

Note: This pattern doesn’t provide any information about using RPA bots. For that information, see the UiPath documentation. You can also use this pattern to set up other RPA bot applications by customizing the installation steps based on your requirements.

This pattern provides the following automations and benefits:

  • Application deployment and sharing: You can build Amazon EC2 AMIs for application deployment and share them across multiple accounts through an EC2 Image Builder pipeline, which uses AWS CloudFormation templates as infrastructure as code (IaC) scripts.

  • Amazon EC2 provisioning and scaling: CloudFormation IaC templates provide custom computer name sequences and Active Directory join automation.

  • Observability and monitoring: The pattern sets up Amazon CloudWatch dashboards to help you monitor Amazon EC2 metrics (such as CPU and disk usage).

  • RPA benefits for your business: RPA improves accuracy because robots can perform assigned tasks automatically and consistently. RPA also increases speed and productivity because it removes operations that don’t add value and handles repetitious activities.

Prerequisites and limitations

Prerequisites

Architecture

Target architecture for setting up RPA bots on Amazon EC2
  1. The administrator provides the base Windows AMI in the ec2-image-builder.yaml file and deploys the stack in the CloudFormation console.

  2. The CloudFormation stack deploys the EC2 Image Builder pipeline, which includes the following resources:

    • Ec2ImageInfraConfiguration

    • Ec2ImageComponent

    • Ec2ImageRecipe

    • Ec2AMI

  3. The EC2 Image Builder pipeline launches a temporary Windows EC2 instance by using the base AMI and installs the required components (in this case, UiPath Studio).

  4. The EC2 Image Builder removes all the host information and creates an AMI from Windows Server.

  5. You update the ec2-provisioning yaml file with the custom AMI and launch a number of EC2 instances based on your requirements.

  6. You deploy the Count macro by using a CloudFormation template. This macro provides a Count property for CloudFormation resources so you can specify multiple resources of the same type easily.

  7. You update the name of the macro in the CloudFormation ec2-provisioning.yaml file and deploy the stack.

  8. The administrator updates the ec2-provisioning.yaml file based on requirements and launches the stack.

  9. The template deploys EC2 instances with the UiPath Studio application.

Tools

AWS services

  • AWS CloudFormation helps you model and manage infrastructure resources in an automated and secure manner.

  • Amazon CloudWatch helps you observe and monitor resources and applications on AWS, on premises, and on other clouds.

  • Amazon Elastic Compute Cloud (Amazon EC2) provides secure and resizable compute capacity in the AWS Cloud. You can launch as many virtual servers as you need and quickly scale them up or down.

  • EC2 Image Builder simplifies the building, testing, and deployment of virtual machines and container images for use on AWS or on premises.

  • Amazon EventBridge helps you build event-driven applications at scale across AWS, existing systems, or software as a service (SaaS) applications.

  • AWS Identity and Access Management (IAM) helps you securely control access to AWS resources. With IAM, you can centrally manage permissions that control which AWS resources users can access. You use IAM to control who is authenticated (signed in) and authorized (has permissions) to use resources.

  • AWS Lambda is a serverless, event-driven compute service that lets you run code for virtually any type of application or backend service without provisioning or managing servers. You can call Lambda functions from over 200 AWS services and SaaS applications, and pay only for what you use.

  • Amazon Simple Storage Service (Amazon S3) is a cloud-based object storage service that helps you store, protect, and retrieve any amount of data..

  • AWS Systems Manager Agent (SSM Agent) helps Systems Manager update, manage, and configure EC2 instances, edge devices, on-premises servers, and virtual machines (VMs).

Code repositories

The code for this pattern is available in the GitHub UiPath RPA bot setup using CloudFormation repository. The pattern also uses a macro that’s available from the AWS CloudFormation Macros repository.

Best practices

  • AWS releases new Windows AMIs each month. These contain the latest OS patches, drivers, and launch agents. We recommend that you use the latest AMI when you launch new instances or when you build your own custom images.

  • Apply all available Windows or Linux security patches during image builds.

Epics

TaskDescriptionSkills required

Set up an EC2 Image Builder pipeline.

  1. Clone the UiPath RPA bot setup using CloudFormation repository, or download the ec2-image-builder.yaml template from the repository.

  2. Sign in to the AWS Management Console, and open the AWS CloudFormation console.

  3. Choose Create stack.

  4. In the Specify template section, choose Upload a template file.

  5. Locate and upload the ec2-image-builder.yaml template from your computer, and then choose Next.

  6. Provide input parameters for your stack or accept the default values. Choose Next.

    Note: The number and values of parameters might vary depending on your input values.

  7. Optionally, configure stack options, and then choose Next.

  8. Review your stack details.

  9. At the end of the screen, select the check box to acknowledge capabilities, and then choose Submit.

  10. Monitor the stack’s progress. When the status is CREATE_COMPLETE, the deployment is ready.

AWS DevOps

View EC2 Image Builder settings.

The EC2 Image Builder settings include infrastructure configuration, distribution settings, and security scanning settings. To view the settings:

  1. Open the EC2 Image Builder console.

  2. From the navigation pane, navigate to various Image Builder settings.

Note: As a best practice, you should make any updates to EC2 Image Builder through the CloudFormation template only.

AWS DevOps

View the image pipeline.

To view the deployed image pipeline:

  1. On the EC2 Image Builder console, choose Image pipelines from the navigation pane.

  2. Select the image pipeline you created.

  3. View the configuration details of the output images, image recipe, infrastructure configuration, distribution settings, Amazon EventBridge rules, and tags.

AWS DevOps

View Image Builder logs.

EC2 Image Builder logs are aggregated in CloudWatch log groups. To view the logs in CloudWatch:

  1. Open the CloudWatch console.

  2. In the navigation pane, choose Logs, Log groups.

  3. Choose the log group name. EC2 Image Builder logs are aggregated in the log group /aws/imagebuilder/XXX.

  4. Check the latest logs in the respective log stream for any errors encountered when running the image pipeline.

EC2 Image Builder logs are also stored in an S3 bucket. To view the logs in the bucket:

  1. Open the Amazon S3 console.

  2. In the Buckets list, choose the bucket name. The logs are aggregated in the S3 bucket <stack-name>-XXXXXX.

AWS DevOps

Upload the UiPath file to an S3 bucket.

  1. Download the .msi file for UiPath Studio from the location https://download.uipath.com/UiPathStudioCommunity.msi.

  2. Upload the file to an S3 bucket.

  3. Update the bucket name and file key in the ec2-image-builder.yaml template, in the user data section, line number 310.

AWS DevOps
TaskDescriptionSkills required

Deploy the Count macro.

  1. Clone or download the Count CloudFormation macro.

  2. Navigate to the Count folder.

  3. You will need an S3 bucket to store the CloudFormation artifacts. If you don't have an S3 bucket already, create one with the name aws s3 mb s3://<bucket name>.

  4. Package the Count macro template. The template uses the AWS Serverless Application Model (SAM), so it must be transformed before you can deploy it.

    aws cloudformation package \ --template-file template.yaml \ --s3-bucket <your bucket name here> \ --output-template-file packaged.yaml

    For example:

    aws cloudformation package \ --template-file template.yaml \ --s3-bucket count-macro-ec2 \ --output-template-file packaged.yaml
  5. Deploy the packaged template to create a CloudFormation stack.

    aws cloudformation deploy \ --stack-name Count-macro \ --template-file packaged.yaml \ --capabilities CAPABILITY_IAM

If you want to use the console, follow the instructions in the previous epic or in the CloudFormation documentation

DevOps engineer

Test the Count macro.

To test the macro's capabilities, try launching the example template that’s provided with the macro. 

aws cloudformation deploy \ --stack-name Count-test \ --template-file test.yaml \ --capabilities CAPABILITY_IAM
DevOps engineer
TaskDescriptionSkills required

Deploy the Amazon EC2 provisioning template.

To deploy EC2 Image Pipeline by using CloudFormation:

  1. Download the ec2-provisioning.yaml template from the GitHub repository, or locate it on your computer if you cloned the repository.

  2. Open the CloudFormation console.

  3. Repeat the steps from the first epic (or follow the instructions in the CloudFormation documentation) to deploy ec2-provisioning.yaml.

AWS DevOps

View Amazon EC2 settings.

Amazon EC2 settings include security, networking, storage, status checks, monitoring, and tags configurations. To view these configurations:

  1. Open the Amazon EC2 console.

  2. In the navigation pane, choose Instances, and then select the EC2 instance that was created by the Amazon EC2 provisioning template.

  3. In the instance summary, select the tabs to view the corresponding Amazon EC2 settings.

AWS DevOps

View the CloudWatch dashboard.

  1. Open the CloudWatch console.

  2. In the navigation pane, choose Dashboards.

  3. Choose the dashboard that has your stack name.

Note: After you provision the stack, it takes time to populate the dashboard with metrics.

The dashboard provides these metrics: CPUUtilization, DiskUtilization, MemoryUtilization, NetworkIn, NetworkOut, StatusCheckFailed.

AWS DevOps

View custom metrics for memory and disk usage.

  1. On the CloudWatch console, choose Dashboards.

  2. In the navigation pane, choose Metrics, All metrics.

  3. Choose Custom namespaces, CWAgent.

AWS DevOps

View alarms for memory and disk usage.

  1. On the CloudWatch console, in the navigation pane, choose Dashboards.

  2. Choose All alarms.

AWS DevOps

Verify the snapshot lifecyle rule.

  1. Open the Amazon EC2 console.

  2. In the navigation pane, choose Lifecycle Manager.

  3. Verify the settings for the AMI lifecycle.

AWS DevOps
TaskDescriptionSkills required

Delete the stacks.

When your PoC or pilot project is complete, we recommend that you delete the stacks you created to make sure that you aren’t charged for these resources.

  1. Open the AWS CloudFormation console

  2. In the navigation pane, choose Stacks, and then select one or both stacks you created earlier that you want to delete. The stack must be currently running.

  3. In the stack details pane, choose Delete.

  4. When prompted, choose Delete stack.

Important: The stack deletion operation can't be stopped after it begins. The stack proceeds to the DELETE_IN_PROGRESS state.

If the deletion fails, the stack will be in the DELETE_FAILED state. For solutions, see Delete stack fails in the AWS CloudFormation troubleshooting documentation.

For information about protecting stacks from being accidentally deleted, see Protecting a stack from being deleted in the AWS CloudFormation documentation.

AWS DevOps

Troubleshooting

IssueSolution

When you deploy the Amazon EC2 provisioning template, you get the error: Received malformed response from transform 123xxxx::Count.

This is a known issue. (See the custom solution and PR in the AWS CloudFormation macros repository.)

To fix this issue, open the AWS Lambda console and update index.py with the content from the GitHub repository

Related resources

GitHub repositories

AWS references

Additional references