AWS Builder Center
How to Track Patient Report Access on AWS with DynamoDB and CloudWatch

How to Track Patient Report Access on AWS with DynamoDB and CloudWatch

Track patient report access on AWS using DynamoDB, CloudWatch, and CloudTrail. Separate authorization, download-link generation, and S3 retrieval events to build a clearer audit trail.

Love to Learn Tech especially AI things.
A patient clicks “Download Report” in a healthcare portal. The backend checks their permissions, generates an Amazon S3 presigned URL, and returns it to the browser.
Can the clinic now record that the patient downloaded the report?
Not yet.
The backend knows that it authorized access and generated a link. The patient might close the browser before using it. The S3 request might fail. Someone could also copy the link and use it from another device.
Useful report-access tracking starts by separating these events.
This article explains how to use Amazon DynamoDB for application audit records, Amazon CloudWatch for operational monitoring, and AWS CloudTrail data events for evidence of S3 object requests.
The example assumes an existing patient portal with authentication, private S3 storage, and an endpoint that generates short-lived download URLs.

1. Decide What Each Event Actually Proves

Avoid using a single event called  REPORT_DOWNLOADED  for every stage of the workflow.
Use explicit event names instead.
Event
What it tells you
What it does not prove
 REPORT_ACCESS_DENIED 
The application rejected an access request
That no other access path exists
 REPORT_ACCESS_AUTHORIZED 
The application approved access at that moment
That a URL reached the browser
 REPORT_URL_GENERATED 
The backend generated a download URL
That the URL was used
S3  GetObject  event
S3 received an object retrieval request; inspect the result for errors
That a specific person read the report
 REPORT_OPEN_REPORTED 
The client reported opening a report
That the patient read or understood it
A successful object request provides stronger evidence of retrieval than a generated link. It still does not establish that the browser saved the complete file or that a human reviewed its contents.
Make these distinctions visible in staff dashboards and support tools.

2. Separate the Application and Storage Evidence

A practical design uses three evidence sources:
DynamoDB stores application decisions. Record the authenticated actor, clinic, report reference, decision, timestamp, and application request ID.
CloudWatch supports operations. Use structured logs and metrics to investigate errors, authorization failures, and audit-write failures.
CloudTrail records selected S3 object activity. Enable S3 data events for the report bucket or relevant object prefix so storage requests can be investigated separately.
These sources answer different questions:
  • Did the portal authorize the request?
  • Did the application record its decision successfully?
  • Did S3 receive a request for the object?
  • Did that storage request return an error?
CloudWatch application logs alone cannot observe a browser downloading directly from S3 after Lambda returns a URL.

3. Build a Small Audit Record

Suppose a patient requests a report from Clinic A.
The server obtains the actor identity from verified authentication claims. It loads the report metadata and checks the patient’s relationship to the report and clinic.
Only then does it write an authorization event.
An illustrative DynamoDB item might look like this:
{
"PK": "CLINIC#c_42#DAY#2026-11-05",
"SK": "EVENT#2026-11-05T09:10:22.345Z#e_8f31",
"eventType": "REPORT_ACCESS_AUTHORIZED",
"actorRef": "u_290",
"reportRef": "r_815",
"requestId": "req_7a93",
"decision": "ALLOW",
"schemaVersion": 1
}
The clinic-and-day partition supports a simple query: “Show this clinic’s events for this date.”
For a small pilot, this can be a useful starting point. A busy deployment may need sharded partitions and additional indexes based on measured traffic and investigation requirements.
Avoid placing patient names, diagnoses, report text, or presigned URLs in the record.
Opaque references still require protection. If another system can map them back to patients, they remain sensitive.

4. Write the Audit Event Before Returning the Link

The following Python helper demonstrates a conditional audit write. It is one component of the download endpoint, rather than a complete authentication or authorization implementation.
import os
from datetime import datetime, timezone
from uuid import uuid4

import boto3

table = boto3.resource("dynamodb").Table(
os.environ["AUDIT_TABLE"]
)

def record_report_event(
*,
clinic_ref,
actor_ref,
report_ref,
request_id,
event_type,
decision
):
now = datetime.now(timezone.utc)
timestamp = now.isoformat(timespec="milliseconds")
event_id = uuid4().hex

item = {
"PK": (
f"CLINIC#{clinic_ref}"
f"#DAY#{now.date().isoformat()}"
),
"SK": f"EVENT#{timestamp}#{event_id}",
"eventType": event_type,
"actorRef": actor_ref,
"reportRef": report_ref,
"requestId": request_id,
"decision": decision,
"schemaVersion": 1
}

table.put_item(
Item=item,
ConditionExpression=(
"attribute_not_exists(PK) "
"AND attribute_not_exists(SK)"
)
)

return event_id
The condition prevents overwriting an existing item with the same key. The random event ID does not deduplicate retried application requests. If that is required, introduce a stable operation identifier and define which repeated events should be treated as duplicates.
In the endpoint, use this sequence:
  1. Verify the authenticated identity.
  1. Load the report metadata from a trusted source.
  1. Check clinic membership and report-level permissions.
  1. Persist the authorization decision.
  1. Generate a short-lived URL for the approved object and, where applicable, its version.
  1. Persist  REPORT_URL_GENERATED .
  1. Return the URL with a response policy that prevents caching.
Do not accept a patient ID or S3 object key from the browser as proof of authorization.

Decide What Happens When the Audit Write Fails

For this example, access fails closed: if a required audit write fails, the endpoint returns a temporary error and does not return the URL.
That makes audit persistence a dependency of report access. The clinic must understand the availability consequence.
A different design could use a durable event queue, but it must account for delivery failures, retries, and recovery. Logging an exception and continuing does not provide a reliable audit trail.
Also avoid logging the complete endpoint response: it contains the download credential.

5. Enable Storage-Level Tracking

Configure CloudTrail S3 data events for the report objects you need to monitor. Object-level data events require explicit configuration; do not assume ordinary management-event history includes report downloads.
For an investigation, inspect fields such as:
  • Event time and API operation.
  • Bucket and object key.
  • Object version, where available.
  • AWS principal associated with the request.
  • Request identifier.
  • Error information.
  • Authentication method, where available.
A presigned request uses the permissions of the signing principal. The storage event does not automatically identify the authenticated patient from the portal.
Keep an application-side mapping between the report reference and its stored object version. Investigators can compare that mapping with storage activity and timing.
However, if several links point to the same object, timing and object identity alone may not identify which link was used. Shared links further weaken attribution.
For the staff interface, use wording such as:
A successful S3 retrieval request was observed for this report version.
Avoid turning that evidence into:
This patient read the report.

6. Use CloudWatch to Detect Operational Problems

Write a small, structured operational event after successful audit persistence:
{
"eventType": "AUDIT_WRITE_SUCCEEDED",
"requestId": "req_7a93",
"auditEventId": "e_8f31",
"outcome": "SUCCESS"
}
Keep report details in the restricted audit store when they are unnecessary for operational troubleshooting.
A CloudWatch Logs Insights query can help identify audit-write errors:
fields @timestamp, requestId, errorCode
| filter eventType = "AUDIT_WRITE_FAILED"
| sort @timestamp desc
| limit 50
Useful alerts include:
Signal
What to investigate
Audit-write failures
DynamoDB permissions, throttling, connectivity, or application errors
Increased access denials
Broken permissions, stale sessions, or suspicious requests
Increased download-endpoint errors
Metadata lookup failures or URL-generation problems
Missing expected audit traffic
Logging changes, deployment issues, or an interrupted event path
Emit failure events without including request bodies, authorization headers, or generated URLs.

7. Protect the Audit Trail

An audit table is not automatically immutable.
Give the application role only the actions it needs. Keep update and delete permissions away from the normal audit-writing path. Restrict audit queries to authorized staff and enforce clinic boundaries server-side.
If the organization requires tamper-resistant retention, design a separate protected archival path. Backups help recovery, but they do not by themselves establish that an audit record was never changed.
Set retention separately for operational logs, application audit events, and storage activity.
DynamoDB TTL can support eventual cleanup where appropriate. It is asynchronous, so it should not be treated as an exact deletion deadline. Select retention periods through the organization’s applicable policies rather than copying an arbitrary duration from a tutorial.

8. Test the Gaps Before Launch

Test
Expected result
Patient requests another patient’s report
Access denied; no URL returned
Clinic A user requests Clinic B’s report
Access denied
Authorized patient never uses the URL
Application events exist; no retrieval should be inferred
Required audit write fails
Temporary error; no URL returned
URL is used after expiry
Request rejected under the applicable expiry conditions
Report is replaced
Audit evidence retains the intended report-version reference
URL is copied to another browser
Demonstrates that possession of the link can permit access
Logging configuration changes
Automated checks detect missing expected events
Also inspect real logs for accidental disclosure. Successful functional tests do not reveal every sensitive field that middleware or exception handlers might record.

Conclusion

A trustworthy patient-report history distinguishes authorization, URL generation, storage retrieval, and client-reported activity.
Use DynamoDB to record application decisions, CloudWatch to detect operational failures, and CloudTrail data events to investigate S3 requests. Preserve the limits of each source when presenting the results.
The most useful audit dashboard tells clinic staff exactly what the system observed—and leaves unsupported conclusions out.
Technical reference basis: AWS documentation for identifying presigned requests, S3 object-level CloudTrail logging, and DynamoDB Time to Live. Code is illustrative and requires integration and deployment testing.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article