AWS Builder Center
How to Build Secure Patient Report Downloads with Amazon S3 Presigned URLs

How to Build Secure Patient Report Downloads with Amazon S3 Presigned URLs

Build patient report downloads with Amazon S3 presigned URLs. Explore authorization checks, URL expiry, report versioning, and practical failure tests for a clinic portal.

A patient portal can keep PDF reports in a private Amazon S3 bucket while allowing an authorized patient to download a specific file directly. The backend checks access, generates a short-lived presigned URL, and returns it to the browser. S3 handles the document transfer.
The difficult part is deciding who may receive that URL. Signing a request proves that AWS credentials permitted the operation. Your application must first establish that the signed-in person may read this particular report.
This walkthrough describes a reference design for a clinic portal. The Python example demonstrates the signing step. Identity verification, database access, infrastructure deployment, and audit storage must be implemented around it before using the flow with real patient records.

Start with a bounded patient journey

A patient signs in, opens the reports page, and selects a released laboratory report. The browser submits its application report ID to an authenticated endpoint. The backend loads the report record, checks the patient's access, records the authorization decision, and signs a GET request for the corresponding S3 object.
Use an opaque application ID such as  report_7f32  in the request. Store the bucket, object key, owning clinic, patient identity, release status, and optional S3 version ID in trusted backend metadata. Object names can also use opaque identifiers. Keep patient names and medical details out of object keys because keys can appear in operational records.
Stage
Input
Required decision
Sign-in
Identity provider session
Is the token valid for this application?
Report lookup
Application report ID
Does a report record exist?
Authorization
Verified identity and report metadata
May this person read this released report?
Signing
Backend-controlled bucket and key
Can the download role access this exact object?
Download
Short-lived signed request
Does S3 accept the signature and applicable policies?
A valid login alone is insufficient. The authorization rule must include the report owner and clinic boundary. Caregivers, guardians, and delegated staff need explicit relationship and permission rules if the product supports them.

Configure private storage and limited signing permissions

Enable S3 Block Public Access and use bucket ownership settings that avoid unintended ACL-based access. Require encrypted transport and configure encryption at rest according to the deployment's requirements. For SSE-KMS objects, account for the signer's required KMS permissions and the applicable key policy.
Give the Lambda execution role only the read permissions needed for the report storage scope. If version-specific downloads are used, include the appropriate version read permission. Keep upload and administrative permissions in separate roles when the responsibilities differ.
The backend should resolve object locations from its own metadata. Accepting a browser-supplied bucket and key would allow a user to ask the signer for other objects within the role's permissions.

Implement the signing step after authorization

The following helper assumes that trusted middleware has verified the identity provider token and that application code has loaded the report from the database.  patient_id  and  clinic_id  represent the application's internal identity mapping. They must come from server-side identity resolution.
import os

import boto3
from botocore.config import Config

REPORT_BUCKET = os.environ["REPORT_BUCKET"]
s3 = boto3.client("s3", config=Config(signature_version="s3v4"))

def issue_report_download(verified_patient, report):
allowed = (
report["patient_id"] == verified_patient["patient_id"]
and report["clinic_id"] == verified_patient["clinic_id"]
and report["status"] == "released"
and report["bucket"] == REPORT_BUCKET
)
if not allowed:
raise PermissionError("Report unavailable")

parameters = {
"Bucket": REPORT_BUCKET,
"Key": report["object_key"],
"ResponseContentType": "application/pdf",
"ResponseContentDisposition": 'attachment; filename="report.pdf"',
"ResponseCacheControl": "private, no-store",
}
if report.get("version_id"):
parameters["VersionId"] = report["version_id"]

signed_url = s3.generate_presigned_url(
ClientMethod="get_object",
Params=parameters,
ExpiresIn=120,
HttpMethod="GET",
)
return {"download_url": signed_url, "expires_in_seconds": 120}
Set  REPORT_BUCKET  in the function configuration. An authenticated API handler calls this helper only after loading metadata and resolving the current patient. It should map failed access checks to a consistent response that does not reveal another patient's report existence.
Apply  Cache-Control: no-store  to the API response containing the signed URL as well. The object response override in the example controls the PDF response. Ensure release status changes and URL issuance have the consistency required by the product, especially where immediate withdrawal is a requirement.
Generating a URL does not prove that the object exists or that a later GET will succeed. Validate completed uploads before publishing report metadata and test the actual download with the deployed role, bucket policy, and encryption configuration.

Treat the URL as a temporary access credential

Anyone possessing an otherwise valid presigned URL can use it within the permissions and policy constraints that apply. A URL may be reused before expiry. Logging out of the portal does not by itself revoke one already issued.
The example chooses 120 seconds as an application setting. Evaluate that duration against accessibility needs, mobile connections, and the time between receiving the response and starting the download. Temporary signing credentials can expire earlier than the URL's requested lifetime. S3 checks expiration when a request begins, so an in-progress transfer can continue after that time. A later retry may need a fresh URL.
Avoid placing the complete URL in analytics, application logs, support tickets, or chat messages. Review browser error reporting and session recording tools as well. Store structured audit events with an opaque report ID, actor ID, decision, and correlation ID under appropriate access controls.
An issuance audit event records that access was granted. It does not prove the patient completed a download or read the document. If object access auditing is required, configure the relevant S3 data event coverage and retention separately and estimate its cost.

Decide how report replacement and withdrawal work

An unversioned object key can return new content after an overwrite. For report corrections, choose immutable object keys or bind downloads to an explicit S3 version and retain the matching metadata. Keep a record of which version was released to the patient.
If staff withdraw a report, prevent new URL issuance immediately according to the application's consistency rules. A previously issued URL may remain usable until it expires unless access to the underlying object or credentials is also changed. Define that behavior before promising instant revocation.
A bucket policy can enforce a maximum signature age as an additional control. AWS documents  s3:signatureAge  in milliseconds. Test a narrowly scoped policy with every legitimate access path before applying a broad restriction.

Test the failure cases before a clinic pilot

Test
Expected result
Patient requests their released report
Authorized URL and successful object download
Patient changes the report ID to another patient's ID
No URL is issued
User requests a report in another clinic
Access denied by the application's tenant rule
Report remains in draft
No patient download URL
URL is used after expiry
S3 denies the new request
URL is copied before expiry
Possessor may use it, demonstrating the bearer-token behavior
Signing role lacks object or KMS access
Download fails and monitoring identifies the configuration issue
Report is replaced
Version policy determines exactly which document is served
Exercise the download from an actual browser. A simple navigation download and a JavaScript fetch have different cross-origin requirements. Configure S3 CORS for the approved portal origins, methods, and headers if the frontend needs cross-origin fetch access. CORS governs browser behavior and does not replace authorization.

Estimate the cost of the flow

Separate stored report volume from download traffic. If 1,000 new reports arrive each month at an average of 5 MB, document storage grows by about 5 GB per month before versions or replicas. If patients download 2,000 reports of that size, monthly outbound document traffic is about 10 GB.
Budget S3 storage, read and write requests, outbound transfer, Lambda, API Gateway, and any selected KMS and audit services. Direct S3 delivery keeps file bytes out of the application function's response path. Measure authorization latency and failed download rates alongside the bill.
For a healthcare deployment, confirm applicable agreements, service eligibility, access controls, and retention requirements for the region and operating model. AWS provides infrastructure capabilities. The clinic and delivery team still own the application's authorization and handling of patient information.

Before rollout, demonstrate one legitimate download, one cross-patient denial, one expired URL, and one corrected report. Those four checks expose more about the design than a successful signing call alone.

Sources consulted on 4 November 2026. Amazon S3 User Guide, Download and upload objects with presigned URLs. AWS Prescriptive Guidance, Establishing guardrails and monitoring for presigned URLs. Boto3 reference, generate_presigned_url. AWS HIPAA Eligible Services Reference.
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