AWS Metrics Scripting

With the AWS Metrics Gem set up, clients can generate and submit metrics events using Script Canvas, Lua, or C++. The following examples demonstrate using Script Canvas and Lua to script behavior. Refer to Using the C++ API with the AWS Metrics Gem for C++ examples.

Script Canvas

Example: Submitting a metrics event

The following image shows how to submit a metrics event and listen to the success or failure notification with the AWS Metrics nodes.

Script Canvas graph example of submitting a metrics event

To do:

Break this image into smaller pieces and describe each one.

A GitHub issue has been created for this task here.


The following script provides a simple example of calling the AWS Metrics API using Lua.

-- Create a new metrics attribute.
attribute = AWSMetrics_MetricsAttribute()

-- Set the name of the metrics attribute.

-- Set the value of the metrics attribute.
-- You can set string, integer, or double as the attribute value.
-- Call SetStrValue, SetIntValue, or SetDoubleValue for the corresponding value type.

-- Add the attribute to the metrics attribute list.
attributeList = AWSMetrics_AttributesSubmissionList()
-- Generate a new metrics event using the metrics attribute list and submit it.
AWSMetricsRequestBus.Broadcast.SubmitMetrics(attributeList.attributes, "event_source", true)
-- Flush the buffer and send all the metrics.

You can also add multiple metrics attributes to an event. Custom metrics attributes not included in the event JSON schema are added to the event_data field as a flat JSON dictionary.

The metrics event is validated against a JSON schema before submission. The event is dropped if any of the required attributes are missing, or if the attribute value doesn’t match the expected pattern.

Capturing notifications

To capture notifications in Lua, connect to the AWSMetricsNotificationBus bus during activation, and disconnect from it during deactivation, as shown in the following example.

function sample:OnActivate()
    -- Connect to the AWSMetricsNotificationBus bus.
    self.metricsNotificationHandler = AWSMetricsNotificationBus.Connect(self, self.entityId)

function sample:OnSendMetricsSuccess(requestId)
    -- Do something after metrics events send successfully.
function sample:OnSendMetricsFailure(requestId, errorMessage)
    -- Do something when metrics events fail to send.
function sample:OnDeactivate()
    -- Disconnect from the AWSMetricsNotificationBus bus.