Skip to content

Is AWS Lambda HIPAA compliant? Where PHI leaks in serverless

Illustration of a folder marked PHI linked by a path of glass tiles to a server stack marked AWS Lambda

The short answer: AWS Lambda is on AWS’s list of HIPAA eligible services, so once your organization has signed the AWS Business Associate Addendum (BAA), you can use Lambda to process protected health information (PHI). That does not make Lambda, or anything you build on it, HIPAA compliant. Compliance belongs to your organization: its policies, its risk analysis, its agreements and the way its systems are configured. AWS says so on the same list: customers must configure eligible services consistent with HIPAA.

The useful question is what the BAA leaves to your team. For a Lambda function, most of the answer is in what the function writes without anyone deciding to. Our position: if a function can see PHI, its logs, failure records and traces can keep a copy of it unless the code or its configuration decides otherwise. The BAA does not move that decision to AWS, and running the function on a platform does not move it to the platform.

We wrote about the organizational side (partners, training and the framework around a Business Associate) in Inside Vinta’s HIPAA compliance blueprint. This post is the technical side: where PHI escapes a serverless function, the control that closes each gap and what that control costs. It is a technical map, not a compliance determination.

Key takeaways

Eligible, not compliant

Lambda is a HIPAA eligible service, covered once your organization signs the AWS BAA. Compliance stays with your organization.

Where PHI leaks

Log output, asynchronous retries, the dead-letter queues and traces you turn on, and environment variables can each keep a copy of what a function sees.

The rule that closes most of it

Log and pass record IDs, never field values. CloudWatch masking is a backstop, not the control.

What stays with your team

KMS keys you control, a least-privilege role for each function, CloudTrail on and a deliberate decision about the VPC.

What the AWS BAA covers, and what it leaves to you

The BAA settles where PHI may be processed: in eligible services, under AWS’s agreement. The services you would pair with Lambda are on the same list: CloudWatch Logs, KMS, CloudTrail, SQS, X-Ray and Secrets Manager.

The agreement does not decide what your code sends to those services. A console.log of a patient object goes to an eligible service, under the BAA. It is still a copy of PHI, in a log group that more people can read, for longer, than the record it came from. Each place below is the same: inside the BAA’s scope, and still your team’s decision.

Where PHI leaks in a Lambda function

Where PHI can land When it happens The control What it costs
CloudWatch Logs The function prints an event, a body or a field Log request IDs and record IDs only; masking as a backstop Debugging goes through the record, not the log
Retries An asynchronous invocation fails, or an event arrives twice Idempotent handlers An idempotency key per event and a place to check it
Dead-letter queues and on-failure destinations You configured one and an invocation fails Record IDs in events; your KMS key, short retention, few readers Another store to encrypt and watch
Environment variables Someone puts PHI or a credential there No PHI; credentials in Secrets Manager A call at start-up and a few lines of code
X-Ray traces Tracing is on and annotations or attributes carry values IDs only in annotations; check what instrumentation captures Less detail in a trace

Log output

Whatever a function prints goes to CloudWatch Logs. It is the most common leak and the easiest to make: a debug line that prints the incoming event, an error handler that logs the request body.

The control is a decision at write time: log request IDs and record IDs, never field values. Our logging standards set the same rule (IDs only), and it applies inside a function too:

Js
export const handler = async (event, context) => {
  const { recordId } = event;

  // IDs only: the request ID traces the run, an opaque record ID finds the data.
  // Never the body, and never an identifier such as a medical record number.
  console.log(JSON.stringify({ msg: 'intake received', requestId: context.awsRequestId, recordId }));

  // ...
};

CloudWatch Logs can also mask sensitive data with a data protection policy. Treat it as a backstop, not the control: masking applies to log events that arrive after the policy is in place, not to what is already stored, and anyone with the permission to unmask still sees the values.

The cost is in debugging. When something fails, the log tells you which record, and you read that record where its own access controls and audit trail apply.

Failure paths: retries and dead-letter queues

When a function invoked asynchronously fails, Lambda retries it twice by default, and an event can be delivered more than once even without a failure. If you configure a dead-letter queue, the failed event lands there as it was, payload included. An on-failure destination (a queue, a topic, a bucket, another function or an event bus) receives a record of the invocation instead, and that record carries the same payload plus the function’s response.

There are two controls. First, keep PHI out of the event where you can: pass a record ID and let the function read the record. Second, when the payload has to carry PHI, treat wherever failures land as a PHI store: encrypt it with a KMS key you control, keep its records for a short time and limit who can read them.

Because retries and duplicates happen, make handlers idempotent, so a second delivery does not send a second message or write a second record. The cost is real work: an idempotency key for each event and a place to check it.

Environment variables

Lambda encrypts environment variables at rest. With the default AWS managed key, anyone allowed to read the function’s configuration can read the values. With your own KMS key, they also need permission to decrypt with that key, which narrows who sees them but still makes them part of the function’s configuration. Keep PHI out of them. Keep credentials in Secrets Manager and read them at runtime: access there is a separate permission that you grant only to the function’s role. The cost is a call when the function starts and a few more lines of code.

Traces

X-Ray records a trace of each request, and you can attach annotations and metadata to it. A trace is one more data store: X-Ray keeps it for 30 days, and it has its own readers. If a function that handles PHI needs tracing, put IDs in annotations, never values, and check what your instrumentation captures on its own before you turn it on.

The X-Ray SDKs and daemon have been in maintenance mode since February 25, 2026, and AWS recommends OpenTelemetry to send traces to X-Ray. The rule does not change with the instrumentation: IDs in span attributes, never values.

Around all of them: the role, the audit trail and the network

  • A least-privilege execution role for each function. It reads the one table or queue it needs and nothing else. The cost is more roles to keep up to date.
  • CloudTrail. It records API activity in the account, which is the trail you need when someone asks who changed a function, read a queue or used a key.
  • A VPC, as a deliberate decision. It lets a function reach private resources and lets you control where its traffic goes. It also adds networking you have to run, such as subnets and endpoints for the AWS services the function calls. Whether your workload needs one is a design decision to make with your compliance owner.

None of this makes a system compliant on its own. It is the part of the work that lives in the code, and it needs your organization’s policies, risk analysis and agreements around it.

If Medplum is your headless EHR backend

This part is for teams that chose, or are weighing, a headless EHR solution with Medplum as the clinical backend and cloud. Medplum runs its Bots on AWS Lambda. Bots are the serverless functions that hold a product’s backend logic. On hosted Medplum they run as sandboxed Lambdas in Medplum’s environment. On a self-hosted server they run in your own AWS account by default. Everything above applies to a Bot.

The platform does not take over the logging decision. Medplum’s documentation says each Bot run writes an AuditEvent to the server logs, and this cannot be turned off. The AuditEvent carries what the Bot printed, and by default it is also saved in the database. The same rule holds: print references such as QuestionnaireResponse/123, never the answers, and keep credentials in the project’s secrets rather than in the code.

We have written about building Bots for Questionnaire automation. For more on how we build health products on Medplum, see our Medplum development services.

Frequently asked questions

Is AWS Lambda HIPAA compliant?

No service is HIPAA compliant on its own. Lambda is on AWS’s list of HIPAA eligible services, which means your organization can use it for PHI once it has signed the AWS BAA. Compliance belongs to the organization, and part of it is how you configure Lambda and what your code writes. See where PHI leaks in a Lambda function.

Is AWS Lambda covered by the AWS BAA?

Yes. Lambda is a HIPAA eligible service, so it is covered once the AWS BAA is in place. You accept the AWS BAA in AWS Artifact, for a single account or for every account in your organization, so a BAA with AWS does cover Lambda. The BAA does not configure anything for you: AWS states that customers must configure eligible services consistent with HIPAA.

Which AWS services can I use with Lambda for PHI?

The ones on AWS’s list of HIPAA eligible services. The services you would usually pair with Lambda are there: CloudWatch Logs, KMS, CloudTrail, SQS, X-Ray and Secrets Manager. Check the list for any other service before PHI goes through it.

Does a Lambda BAA cover API Gateway, queues and triggers?

Only if each of them is on the list in its own right. Lambda’s eligibility does not extend to the services around it: the trigger that invokes the function (API Gateway, a queue, a bucket), every service the function calls and every place it writes to must each be HIPAA eligible and configured for PHI. Trace one synthetic request from the trigger to the last write, failures included, and check each hop against the list.

Does SOC 2 mean AWS Lambda is HIPAA compliant?

No. A SOC 2 report attests to controls on AWS’s side of the service. HIPAA compliance depends on your organization: the BAA, your policies and risk analysis, and how your functions are configured and what they write. A SOC 2 report is useful evidence about the vendor, not a HIPAA determination about your system.

Can Lambda logs contain PHI?

They can, and they should not. Whatever the function prints reaches CloudWatch Logs, so a function that processes PHI can write logs as long as they carry request IDs and opaque record IDs rather than field values. A log line stays as a copy with its own readers and retention. Our logging standards explain the IDs-only rule.

Does CloudWatch Logs masking make PHI in logs acceptable?

Masking is a backstop, not the control. It applies only to log events that arrive after the data protection policy is in place, and anyone with the permission to unmask still sees the values. Keeping PHI out of log output at write time is what closes the gap.

What happens to PHI when a Lambda invocation fails?

For asynchronous invocations, Lambda retries twice by default and can deliver an event more than once. A dead-letter queue keeps the failed event with its payload, and an on-failure destination keeps a record of the invocation that carries the same payload. Pass record IDs instead of PHI where you can, encrypt those destinations with your own KMS key, keep records briefly and make handlers idempotent.

Do I need a VPC to run a HIPAA workload on Lambda?

It is a design decision for your architecture, made with your compliance owner. A VPC lets a function reach private resources and lets you control where its traffic goes, at the cost of networking you have to run.

References

Book a call

Ready for software that finally fits?

Bring us your care model and find the right technical partner to build it with you.