Cloudwatch Log is an AWS service in which applications or Bash scripts can send data as strings or JSON, then you can find them or build various graphs using the same AWS.
One day, I had a desire to get data from AWS Cloudwatch Log, process it in a special way and present it beautifully as a graph. Google Spreadsheet does a good job with data visualization, and earlier for similar tasks I loaded data into it using Ruby. But the same ruby ​​script needs to be hosted somewhere and periodically run, and all that it will do is to request data from one API (AWS) and put it into another (Spreadsheet). It would be nice if Spreadsheet itself could request data, and it turns out it can, using Google Script. It's amazing how much Google dots really know how.
Google Script allows you not only to create custom functions and macros using JavaScript, but also to access the external API.
AWS has an SDK for JavaScript, so I did not expect any difficulties, but it was not there. It turned out that this SDK being imported into the GS project cannot find the window object and does not work.
')
I had to read the API docks and do the computation of the signature for the request myself. There is nothing technically difficult in this, just stitching strings together and calculating a hash. Therefore, I do not go into details, but simply present my decision on the occasion if someone faces a similar task.
the code is posted on
githubTo check his work you can:
- make a copy of the document
- open "Tools" -> "Script Editor"
- in “File” -> “Project Properties” -> “Script Properties” add the strings “access_key_id” and “secret_access_key” and indicate the values ​​of your API keys in them
- Then open the “Code.gs” file and run the function “dataFromCloudWatch”
- Results will be visible in “View” -> “Performance Report”. This is for simplicity. In a real problem, the answer is easy to parse and insert values ​​into the corresponding cells of the spreadsheet.
The code uses the
GetMetricStatistics request
, but if necessary, you can request any other method, the signature algorithm will remain unchanged.
Update: I completely forgot to mention that you can configure the periodic launch of this function through the “Resources” -> “Triggers of the current project”.