Abhiek187 / aws-shop

A basic shopping app that utilizes various AWS services
https://d23f1hp5lvetow.cloudfront.net/
The Unlicense
3 stars 0 forks source link

Create CloudWatch/Pinpoint dashboard #5

Closed Abhiek187 closed 2 months ago

Abhiek187 commented 1 year ago

Can try an internet monitor for CloudFront: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-internetmonitor-monitor.html

Or a synthetics canary to track API Gateway requests: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-synthetics-canary.html

Abhiek187 commented 2 months ago

Was reading this blog about Lambda Powertools and it got me thinking about how we could collect metrics in this app.

image

POWERTOOLS_METRICS_NAMESPACE: "ecommerce-app"
POWERTOOLS_SERVICE_NAME: "shopping-cart"
from aws_lambda_powertools import Logger, Metrics, Tracer

metrics = Metrics()

@metrics.log_metrics(capture_cold_start_metric=True)
def lambda_handler(event, context):
...
check_out_cart() # Function to process the checkout
metrics.add_metric(name="CartCheckedOut", unit="Count", value=1)

This is the easiest method I've seen for sending business metrics (instead of server metrics like execution time or CPU usage) in CloudWatch. We create a namespace, one or more dimensions, and metrics for each dimension. Then we just call a method to record a unit and value for a metric, simple as it should be. I'll need to figure out how to do the same thing, but on the front-end (and securely).

Namespace: AWSShopApp Dimensions: Service=[Store, AppBar, Profile] Valid units: https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html

Metric ideas (can't create more than 10 custom metrics within the free tier, including dimensions 🥲):

$ aws cloudwatch put-metric-data --namespace AWSShopApp --metric-data file://metric.json
[
  {
    "Dimensions": [
      {
        "Name": "Service",
        "Value": "Store"
      }
    ],
    "MetricName": "DeepRacer",
    "Timestamp": "Wednesday, June 12, 2013 8:28:20 PM",
    "Value": 1,
    "Unit": "Count"
  }
]
Abhiek187 commented 2 months ago

Alternative: Pinpoint Analytics

Endpoints: https://docs.aws.amazon.com/pinpoint/latest/developerguide/integrate-endpoints.html Events: https://docs.aws.amazon.com/pinpoint/latest/developerguide/integrate-events.html

$ aws pinpoint put-events --application-id AWSShopApp --events-request file://events.json
{
  "BatchItem": {
    "UserId": {
      "Endpoint": {},
      "Events": {
        "EventId": {
          "AppPackageName": "com.example.app",
          "AppTitle": "AWS Shop",
          "AppVersionCode": "v1.2.1",
          "Attributes": { "service": "DeepRacer" },
          "ClientSdkVersion": "v3.198.0",
          "EventType": "EventName",
          "Metrics": { "count": 1 },
          "SdkName": "aws-sdk",
          "Session": {
            "Duration": 1000,
            "Id": "SessionId",
            "StartTimestamp": "ISO datetime",
            "StopTimestamp": "ISO datetime"
          },
          "Timestamp": "ISO datetime"
        }
      }
    }
  }
}

Payload details: https://awscli.amazonaws.com/v2/documentation/api/latest/reference/pinpoint/put-events.html

The events pricing is generous, but the endpoints (monthly targeted audience, MTA) pricing is limited if the free tier is really for the first 12 months. Though, I don't think endpoints are required if we don't need to target specific users or devices.