How to Rename Agents Using AWS Lambda and the NetBeez API

By January 5, 2022NetBeez

Automatically Rename Remote Worker Agents based on the employee’s HR profile

This notebook showcases a use-case suitable for anyone managing more than 100 remote worker agents on their BeezKeeper. It actually came out from a request from one of our customers who is managing more than 1000 remote worker agents. They wanted to name the agents with the employee’s first name, last name and office number. The remote worker agent software reports the employee’s ID, which is the same as the laptop’s name, to the NetBeez BeezKeeper server.

Then there is a script running on AWS Lambda, which periodically checks for new agents whose name matches a regular expression representing the ID format, using the NetBeez API. When it finds some, it cross-references that ID with the employee’s profile on the HR software and generates a string with the ID, first name, last name and office number for each agent. It finally submits those names back to the NetBeez server API and they get updated.

This diagram represents the workflow:

API AWS Lambda

In the following sections we will describe how the python script running in the Lambda function can be written to implement the functionality we just described.

Setup your script for NetBeez BeezKeeper API access

The following code will initialize everything needed to enable your script to access the API. If you would like to learn exactly how this setup works, please refer to our previous blog post about using the NetBeez API.

In [1]:

Function to get the agents records

In this section we implement the function that will get the agents which only have the employee ID in their name.

The format of the employee id is id1234567 so a regular expression that matches names which have the ID at the end of it would be id[0-9]{7}$.

Documentation for the endpoint used can be found here:

In [2]:

Function to get the employee information

In this section we implement the HR database lookup. For the sake of demonstration we’ll just use a public API that is generating random names. When you are implementing this workflow you should check the software’s documentation for information on how to get employee names from your HR software.

In [3]:

Function to generate an array of objects containing agent ids and employee names

We now implement the function that generates an array of objects with agent ids and names that will be used as the data pushed back to the NetBeez server to update the agent record names.

In [4]:

Function to push the new agent names back to the NetBeez API

Now that we have all the data transformation function done, we can implement the final step which is the PUT request back to the NetBeez API, which takes as input the output from the generatePayloadFromAgents() function.

Documentation for the endpoint used can be found here:

In [5]:

Final glue for running on AWS Lambda

We finally add some code that will invoke the functions above whenever the Lambda function is invoked. Invoking the Lambda function can be done on a schedule.

More information on how you can install and setup an AWS Lamda function can be found here:

In [6]:

State Before and After running this script

Here is what the agent looked like before running this script: 

before script

Here it is after running this script: 

after script


This article describes a real use-case developed with one of our customers who is managing thousands of remote worker agents on a NetBeez dashboard. Manually tracking new agents deployed and figuring out how to name them is time consuming, let alone almost impossible. With this workflow the process is automated to keep your dashboard organized at all times. Currently there is no triggering event available from NetBeez, but we will eventually provide functionality where the NetBeez server can be used to trigger these kinds of automation workflows. For now it needs to be periodically scheduled to run and discover new agents.

More documentation on the NetBeez API can be found here: Other API examples can be found here and here.

The code contained herein is available as a Jupyter Notebook on the NetBeez GitHub account.

Lastly, are there other examples that you want me to share about using the NetBeez API? Just drop a note in the comments section!