Search code examples
amazon-web-servicesamazon-s3amazon-cloudwatch

AWS Cloudwatch: How to monitor a specific S3 object upload frequency


I am looking to troubleshoot an IoT device to test how consistently it uploads a certain object to S3. Specifically, the device uploads an object to s3://mybucket/myprefix/filename.json. The IoT device should upload this file every 60 seconds without fail, so I'm looking to be able to eventually extract e.g. a CSV with timestamps for each ObjectCreated event for that object so that I can plot the deltas in the timestamps.

I assume the right solution involves CloudWatch, but it seems like e.g. creating an Event trigger only lets me trigger e.g. a Lambda function or similar. I am looking for something lighter.

Is this possible to set up in the CloudWatch section directly or how would one go about this?


Solution

  • You need to set up a data plane trail on CloudTrail for that.

    This code is copied from CloudTrail docs with minor modifications:

    aws cloudtrail put-event-selectors --trail-name TrailName \
    --advanced-event-selectors 
    '[
      {
        "Name": "Problematic IOT",
        "FieldSelectors": [
          { "Field": "eventCategory", "Equals": ["Data"] },
          { "Field": "resources.type", "Equals": ["AWS::S3::Object"] },
          { "Field": "eventName", "Equals": ["PutObject""] },
          { "Field": "resources.ARN", "Equals": ["arn:aws:s3:::mybucket/myprefix/filename.json"] }
        ]
      }
    ]'