AWS Builder Center
How to Build Secure Patient Report Uploads with Amazon S3 and AWS Lambda

How to Build Secure Patient Report Uploads with Amazon S3 and AWS Lambda

Build a patient-report upload workflow on AWS with private S3 storage, Lambda, and DynamoDB. Handle file validation, object versions, duplicate events, and approval before patient access.

A clinic employee uploads a PDF report. The progress bar reaches 100%, and the portal immediately makes the document available to the patient.
That workflow skips several important questions.
Was the employee authorized to upload a report for that patient? Did the file arrive intact? Is it actually a supported PDF? Has it passed the required security checks? Could another upload replace the file after it was checked?
A reliable upload workflow separates receiving a file from approving it for patient access.
This article describes a design using Amazon S3 for private storage, AWS Lambda for application logic, and Amazon DynamoDB for upload status. It builds on a patient portal that already supports authenticated staff and authorized report downloads.

1. Define the Upload Rules First

Start with a narrow scope.
For this example, clinic staff upload PDF reports for patients assigned to their clinic. Patients cannot upload files through this endpoint.
Use these illustrative product rules:
Rule
Example
Allowed format
PDF only
Maximum file size
10 MiB
Upload permission lifetime
Five minutes
Initial visibility
Hidden from patients
Publication requirement
Technical validation and required staff approval
Replacement behaviour
Create a new report version
These values are design choices, rather than AWS defaults.
Technical checks also cannot establish that a document belongs to the correct patient. Staff confirmation or a trusted clinical-system mapping remains necessary.

2. Create an Upload Session Before Accepting the File

The browser first requests permission to upload.
The backend verifies the staff identity and checks that the user can attach a report to the selected patient within the selected clinic.
After authorization, it creates an upload-session record:
{
"uploadId": "up_70a8",
"clinicRef": "c_42",
"patientRef": "p_815",
"reportRef": "r_209",
"status": "PENDING_UPLOAD",
"expectedContentType": "application/pdf",
"maximumBytes": 10485760,
"objectKey": "incoming/c_42/up_70a8/report.pdf"
}
Generate the object key on the server. Do not let the browser choose an arbitrary bucket, prefix, patient reference, or existing report key.
Keep patient names and diagnoses out of object keys. Opaque identifiers still require appropriate protection, but they reduce unnecessary disclosure through filenames and operational tools.
Only return upload credentials after the session has been saved successfully.

3. Issue a Restricted Upload Permission

For browser uploads, a presigned POST can express conditions such as an exact object key, a declared content type, and an allowed size range.
The following helper illustrates that part of the workflow:
import os

import boto3
from botocore.config import Config

s3 = boto3.client(
"s3",
config=Config(signature_version="s3v4")
)

MAXIMUM_BYTES = 10 * 1024 * 1024

def create_upload_form(object_key):
return s3.generate_presigned_post(
Bucket=os.environ["INCOMING_BUCKET"],
Key=object_key,
Fields={
"Content-Type": "application/pdf"
},
Conditions=[
{"Content-Type": "application/pdf"},
["content-length-range", 1, MAXIMUM_BYTES]
],
ExpiresIn=300
)
Call this helper only after authorization and session creation.
The browser submits the returned form fields and the file to S3 using multipart form data. Configure bucket CORS for the required website origin and upload method.
The content-type condition checks the declared value. It does not inspect the uploaded bytes or prove that the document is a valid PDF.
A presigned upload permission is also a temporary credential. Keep it out of logs, analytics events, and support screenshots.

4. Keep Incoming Files Separate from Published Reports

Use a private incoming bucket or restricted incoming prefix.
The patient download service must not issue download links for that location.
A separate published bucket provides a clear boundary:
Storage area
Purpose
Patient download access
Incoming
Receive and validate uploads
Denied
Published
Hold approved report versions
Allowed after application authorization
Block public access and restrict the signing role to its required upload location.
Configure encryption, key permissions, and operational access for the deployment. Do not assume that choosing private storage completes the application’s security requirements.
Keep the incoming upload role unable to write directly into the published area.

5. Process a Specific Object Version

An upload permission can potentially be reused while valid. A later upload to the same key can replace the current object, or create another version when versioning is enabled.
This creates a dangerous race if validation checks one version and publication later reads whichever version is current.
Enable versioning for the incoming bucket in this design. Associate each validation job with the exact object version received.
The worker should:
  1. Find the matching upload session.
  1. Verify the event’s bucket and object key.
  1. Record the incoming object version.
  1. Read and validate that exact version.
  1. Publish only that validated version.
If the design does not use versioning, it needs another explicit strategy to prevent files changing between validation and publication.
Generating a unique key reduces accidental collisions. It does not make upload credentials single-use.

6. Validate Before Marking the Report Ready

Validation should cover several independent checks.
Check
Purpose
Session lookup
Reject unexpected objects with no valid upload session
Actual object size
Confirm the received file meets the product limit
File inspection
Confirm supported PDF structure using a maintained parser
Security scanning
Apply the deployment’s malware-detection process
Integrity check
Compare an expected checksum when the workflow supplies one
Patient assignment review
Confirm the report is attached to the intended patient
A filename ending in  .pdf  is insufficient.
A checksum helps detect a mismatch between expected and received bytes. It does not prove that a document is safe, clinically correct, or assigned to the right patient.
Define how the system handles encrypted PDFs, files that cannot be parsed, scanner timeouts, and inconclusive results.
For this example, inconclusive validation keeps the report unavailable. The staff interface shows that further action is required.
Choose processing infrastructure based on file size, scan duration, and tool requirements. Lambda can coordinate the workflow without necessarily performing every scan itself.

7. Handle Duplicate Notifications Safely

S3 event notifications can arrive more than once and may arrive out of order.
Use the bucket, object key, and version identifier to distinguish processing jobs. Persist job state so a repeated notification does not publish another copy or send another patient notification.
An illustrative lifecycle is:
PENDING_UPLOAD
VALIDATING
AWAITING_APPROVAL
READY
REJECTED
Use conditional database updates to enforce permitted transitions.
For example, publication should require both a successful validation result for the selected version and the necessary approval. A delayed event for another version must not overwrite the published report reference.
If a worker claims a job and then crashes, the job needs recovery. Use a bounded processing lease or another retry mechanism rather than leaving the item permanently marked as processing.

8. Publish an Approved Copy

After validation and approval, copy the selected incoming object version into a new, server-generated published key.
Record the published object reference and change the report status to  READY  only after that copy succeeds.
Keep recovery rules for partial failures:
  • If copying fails, the report remains unavailable.
  • If copying succeeds but the database update fails, retry against the same intended publication target.
  • If notification fails after publication, retry notification without publishing the report again.
The download endpoint checks  READY  status and current access permissions before generating a link.
For corrections, create a new report version and retain the appropriate relationship to the previous one. Avoid silently changing the document behind an existing audit reference.

9. Give Staff Accurate Status Messages

An upload progress bar measures transfer progress. It does not measure validation or approval.
Use messages that reflect the actual stage:
Stage
Suggested message
Uploading
“Uploading your file…”
Transfer complete
“File received. Checks are in progress.”
Awaiting approval
“Checks complete. Staff approval is required.”
Ready
“Report is available to the patient.”
Rejected
“This file could not be accepted. Review the reason and upload again.”
Keep failure explanations useful without exposing internal system details.
If the browser closes after transfer, staff should be able to reopen the portal and retrieve the upload status through an authenticated endpoint.

10. Test the Failure Paths

Before launch, test more than a successful upload.
Test
Expected result
Staff requests an upload for another clinic
Permission denied
File exceeds the configured limit
Upload rejected
File declares PDF but contains unsupported data
Validation rejects it
Same upload permission is reused
Versions remain distinct; unchecked content is not published
Duplicate object event arrives
No duplicate publication
Scanner times out
Report stays unavailable
Worker crashes after claiming a job
Recovery mechanism retries safely
Copy succeeds but status update fails
Reconciliation completes or flags the incomplete publication
Patient requests a pending report
Download denied
Use synthetic documents for development and testing. Check that logs exclude document contents, patient details, and upload credentials.

Conclusion

Secure patient-report uploads require a workflow around the file transfer.
Authorize the staff member, create a tracked session, receive the file privately, validate a specific object version, and publish only after the required checks and approval.
That separation makes upload failures recoverable and gives staff a clearer answer to the question that matters: “Is this report ready for the patient?”
Technical note: The code illustrates presigned POST generation. Authentication, session persistence, validation workers, publication, and recovery require implementation 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