An example of retrieving data from AWS Cloudwatch using Google Script

Log Cloudwatch is the AWS which applications or Bash scripts can send data as strings or JSON, then they can find or construct a variety of graphs by means of the same AWS.

Once I had the desire to get the data from the AWS Cloudwatch Log, process them in a special way and beautiful to present as a graph. Google Spreadsheet is good with data visualization, and previously for a similar task I loaded data into it using Ruby. But the same ruby script need somewhere to host and run periodically, and all he will do is to query data from one API (AWS) and place them in another (Spreadsheet). It would be nice if the Spreadsheet itself could query the data, and it turns out he can, using Google Script. It's amazing how much really can Google docks.

Google Script allows you not only to create custom functions and macros using JavaScript, but to access an external API.
AWS SDK is under JavaScript, so I was not expecting any difficulties, but it was not there. It turned out that this SDK is being imported into the project GS cannot find the object "window" not working.

I had to read the API docks and to implement the calculation of the signature for the request. There is nothing technically challenging, just the bonding lines and the hash computation. So I don't go into details, but simply give its decision on the case if someone will face this challenge.


code posted on GitHub

To test it you can:
the
    the
  • make a copy document
  • the
  • to open the "Tools" - > "script Editor"
  • the
  • in "File"- > "project Properties"->"script Properties" to add lines "access_key_id" and "secret_access_key" to indicate the value of their API keys
  • the
  • Then open the file "Code.gs" and start the function "dataFromCloudWatch"
  • the
  • Results will be visible in "View"->"performance Report". This is for simplicity. In a real problem the answer is easy to parse and insert the values into the corresponding spreadsheet cells.


The code uses the request GetMetricStatistics but if necessary you can request any other method, the signature algorithm will remain unchanged.

Update: I forgot to mention that you can configure periodic start this function via the "Resources"-> Triggers"current project".
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

Performance comparison of hierarchical models, Django and PostgreSQL

google life search

Transport Tycoon Deluxe / Emscripten part 2