aws-samples / aws-serverless-connect-wallboard

Sample code for building a serverless wallboard for Amazon Connect.
MIT No Attribution
28 stars 18 forks source link

gethistoricalmetric.py lambda function is giving error while testing . Please update the code to get the historicaldata #19

Closed azConnectaz closed 8 months ago

azConnectaz commented 9 months ago

{ "errorMessage": "unsupported operand type(s) for +: 'int' and 'str'", "errorType": "TypeError", "requestId": "**", "stackTrace": [ " File \"/var/task/get-historical-metrics.py\", line 222, in lambda_handler\n GetConfiguration()\n", " File \"/var/task/get-historical-metrics.py\", line 91, in GetConfiguration\n if time.time() < LastRun+ConfigTimeout:\n" ] }

Brettles commented 9 months ago

Should be fixed now. Was also a bug in render-wallboard.py - fixed there too.

azConnectaz commented 9 months ago

Now bugs are removed but when I am testing this lambda function , I am getting a response as null and nothing is stored in dynamoDB table.

azConnectaz commented 9 months ago

If i see an error in cloudwatch logs , it is giving error did not get any data sources.

Brettles commented 9 months ago

Can you share your wallboard definition file? The GetHistoricalMetrics Lambda function will only retrieve metrics that you have specified that are required for your wallboard. If there is nothing specific then it won't retrieve any metrics.

azConnectaz commented 9 months ago

I am creating different UI or custom dashboard for that frontend part , basically i want historical data in dynamoDB table .How can i store that historical metric data in dynamo DB like we are doing in process-agent-event.py . I just want that this get-historical-metrics.py function get historical metric and put data in dynamo DB table.

azConnectaz commented 9 months ago

I am not familiar with python brettles, Can you please just modify the lambda function to store the historical metric data in dynamoDB table and just share it . It would be really helpful.

Brettles commented 9 months ago

The challenge is that you (might!) have multiple Connect instances and multiple queues within those instances. And there are historical metrics for all of those - so this is an overlapping data namespace; the wallboard can solve that for you.

Start with this:

Now you can create a definition file which tells the wallboard which metrics you want to retrieve. If you want to, you can retrieve all of them - you just need to define them in the file.

Look at the example in the README and there is another example in the original blog post - both are simple but you can add the metrics you want - there is a list in the README.

Once you have created the definition file, import it (instructions are in the README). Then the Lambda will place those metrics into the DynamoDB table. Then you can call the API to retrieve the data (or you can go directly to the DynamoDB table). If you want the data in JSON format just put &json=true on the end of the API call.

Brettles commented 9 months ago

The wallboard is designed to be general-purpose. It you want to retrieve all of the metrics you can call the APIs directly - you can use and AWS SDK you like (you don't have to use Python). But the wallboard is designed so that you don't have to do that - you just define what you want and it gets it for you.

azConnectaz commented 9 months ago

Is it Mandatory to have the definition file to write real time and historical data to DynamoDB. I am trying to execute the wallboard-import.py with the definition file but i don't have admin privilege to my system as it was asking for some dependencies and i don't have administrator access to store or get the dependencies. Can i do this using a lambda function.

Brettles commented 9 months ago

Ok, but bear in mind that the whole point of writing (and importing) a definition file is so that you're not messing around with the database directly. Also: you can only retrieve historic metrics this way, not real-time metrics (that happens in the RenderWallboard function). So some tips:

For each metric you want to retrieve, create a record in DynamoDB with the following attributes:

Once you've added those records the Lambda function will do the job you want. But again: this is the hard way to get this working. If what you want is all (or some of) the metrics for a queue then why not call the Connect APIs using your favourite SDK?

azConnectaz commented 8 months ago

Thank you Brettles. It really helped.