A patient portal can use Amazon Cognito for sign-in, an API Gateway JWT authorizer to validate access tokens, and AWS Lambda to check which patient records the signed-in account can access. The application stores the connection between the account and the patient record, then checks that connection when the user requests a report, appointment, or other private information.
A patient might sign in successfully and still be unable to open a report. Their account could be linked to the wrong clinic, a caregiver grant could have expired, or the report could still be awaiting release. Each of those cases needs a different fix.
What does each AWS service do?
- Amazon Cognito manages sign-in and issues tokens for the portal application.
- Amazon API Gateway validates the token on protected routes and checks the required OAuth scope when configured.
- AWS Lambda checks the signed-in account’s current access to the specific record.
- The application database stores verified links between accounts, patients, and clinics, along with any delegated access grants.
1. Link the account to the right patient during enrollment
Suppose two family members share an email address. The clinic uses that address for appointment communications, and both family members have separate patient records. Automatically linking the portal account to the first matching email could expose one person’s reports to the other.
During enrollment, use the clinic’s identity verification process to confirm which record belongs to the person opening the account. Save the resulting link using the stable account subject from the configured identity provider.
A minimal record might look like this:
{
"accountSubject": "demo-user-290",
"clinicRef": "clinic-42",
"patientRef": "patient-815",
"accessType": "SELF",
"status": "ACTIVE"
}
If the patient later updates their email, the application can keep the same patient-record association. If the clinic needs to correct a mistaken association, record the change and who approved it.
For caregivers, store a separate grant with the permitted patient, scope, expiry, and status. A caregiver who can manage appointments may have a different grant from one authorized to view reports.
2. Check the requested record in Lambda
Take GET /reports/{reportId} as an example. API Gateway validates the access token, then Lambda uses the verified account subject to look up current grants. The backend checks whether the report belongs to a covered patient and clinic, and whether staff have released that report version.
Read the account subject from validated claims
Find the requested report
Check active access to its patient and clinic
Check whether the report version has been released
Return the report or issue a short-lived download URL
Apply the same checks to report lists and individual downloads. A patient who can see a report in a list should go through a fresh authorization check when requesting its file. If a caregiver grant is revoked after a presigned URL has already been issued, the URL can still be usable within its own validity window. Set that window according to how long the clinic can tolerate previously issued access.
3. Test what clinic staff will see in support tickets
Scenario | Expected result |
|---|
A signed-in patient opens their released report | The portal grants access |
A signed-in patient requests another patient’s report | The portal denies access |
An active caregiver tries to view a report with an appointment-only grant | The portal denies report access |
A caregiver grant expires while the browser remains open | Subsequent requests for the patient’s records are denied |
A patient can sign in but their report is awaiting release | The portal keeps the report unavailable |
Use synthetic records for these tests. Log the request ID and an internal reason code, such as GRANT_EXPIRED or REPORT_UNRELEASED . Keep tokens, report contents, and download URLs out of routine logs. Support staff can then distinguish a login issue from an enrollment, access, or report-release issue without opening the patient’s document.
Loading article