How Medplum Bots on AWS Lambda work and when teams need them
A platform or integration team running a self-hosted Medplum on AWS eventually needs server-side logic that reacts to FHIR data without living in a separate service they must patch and scale by hand. Medplum Bots fill that role. According to the Medplum documentation, a Bot is server-side code that runs when something calls it, when a FHIR Subscription fires on a resource change, or when a schedule triggers it. The Bot code, its configuration and its access settings all live inside the Medplum project, so the team can review who can invoke what before anything reaches production. AWS Lambda is one of several execution options for that code, chosen when the team wants a managed, elastic runtime alongside the rest of its AWS estate.
Teams should not assume the Lambda behavior from memory or from older blog posts. The naming of functions, how Medplum-managed functions differ from external functions that the team names and deploys itself, the IAM roles attached to each, and how isolation is enforced all depend on the Medplum version installed and the way the stack was deployed. Confirm these details against the current Medplum self-hosting documentation and the release notes for your exact version before designing around them. Write down the answers to four questions: who creates the function, which IAM role it runs under, which secrets it can read, and where its logs land. Those answers drive every later decision on this page.
The AWS deployment built with CDK and CloudFormation is the recommended self-hosting path in Medplum's docs, so most AWS-hosted teams will already have Bot execution wired into that stack. Kubernetes-based installs handle Bot execution differently, typically through a serverless framework running in the cluster, and that model is covered on the sibling page on running Bots on Kubernetes with Fission. If your organization is choosing between AWS and Kubernetes for Bot runtime, treat the two as separate designs with separate IAM, networking and operations models rather than swapping one for the other during the build. Plan the execution backend before writing Bot code, because moving Bots between backends later changes deployment pipelines, permissions and monitoring.
How a Bot invocation moves from trigger to function
A caller or Subscription writes to the Medplum server, which loads the Bot and its project secrets from PostgreSQL and checks cached state in Redis. The server then invokes the function in the AWS account, where it runs under its own IAM role. The function calls the Medplum FHIR API under the Bot's identity, so every read and write passes through the same access checks as any other client. Results and logs return to the server. Check which credentials the server passes to the function and which ones the function holds directly, because those are the two trust boundaries to review.
Trigger, invocation and data access paths for a Bot on Lambda, with trust boundaries marked.
Medplum-managed functions versus external functions with your own tooling
This table compares the two ways self-hosted Medplum can run Bots on AWS Lambda across ownership, naming, IAM, observability, upgrade coupling and team effort. Read each row against your own AWS governance rules, and treat the right-hand column as the path that adds work your team must own permanently.
| Aspect | Medplum-managed functions | External functions with your own tooling |
|---|---|---|
| Who owns the function | Medplum's deployment creates and updates the Lambda function that runs each Bot | Your team creates the function in your AWS account and wires Medplum to invoke it |
| Naming and deployment | Follows the names and packaging Medplum's deployment uses, with little customization | Follows your existing naming standard, IaC templates and CI/CD pipeline, which you must maintain |
| IAM role design | Uses the execution role that the Medplum deployment provisions, so review focuses on what it grants | Your team designs a dedicated role per Bot or group of Bots, reviewed through your IAM process |
| Logging and monitoring | Logs and alarms follow the deployment's defaults, so confirm where executions appear in CloudWatch | You choose log groups, retention, metrics and alarms, and integrate them with your SIEM or monitoring stack |
| Upgrade coupling | Function code and configuration move with Medplum server upgrades, which follow the sequence in the upgrading guide | Function code can move on your own schedule, but compatibility with each Medplum version must be retested |
| Fit for minimal AWS customization | Strong fit for teams that want the default path and accept Medplum's naming and role defaults | Weak fit unless the team has a clear need to change the default path |
| Fit for strict AWS governance | Weaker fit when auditors require specific role boundaries or naming that the default does not provide | Strong fit when an existing naming standard, IaC pipeline and IAM review process must apply to every function |
| Team effort to run | Lower ongoing effort, mainly verifying each upgrade and reviewing the default role | Higher ongoing effort for IaC, role reviews, function releases and drift checks |
Choosing the execution model by who owns the function
The platform team owns the AWS accounts, the self-hosted Medplum deployment and the upgrade calendar. It decides whether Bot execution stays on the Medplum-managed path or moves to functions the organization names, packages and deploys itself. The self-hosting documentation describes AWS deployment with CDK and CloudFormation as the recommended option, so the platform team already works in that model and inherits its conventions.
- What you gain: one place to watch Lambda invocations, concurrency and errors next to the Medplum server, with one account to budget and report on.
- What you maintain: Lambda runtime versions, the deployment pipeline for any external functions, and concurrency and quota settings in each account and Region.
- Upgrade coupling: Medplum minor versions must be applied in sequence, so confirm whether Bot runtime changes arrive with server upgrades or need separate work on your side.
- Account layout: decide which accounts and Regions hold functions, and who pays for invocations and logs in each one.
- Operating capacity: confirm whether the team can support a second deployment path for functions alongside the managed one.
Before you choose, confirm with Medplum in writing which Lambda behaviors are managed for you and which fall to your team, because that split determines your monthly operating load.
The security team approves the IAM roles, network paths and secret access that every Bot execution depends on. Its decision is about how far each function can reach. A function that can call only the FHIR API it needs, from a known network path, limits the damage a faulty or compromised Bot can do. The choice between managed and external functions changes which roles and paths the team must review.
- What you gain: a smaller blast radius, because each execution role can be limited to the resources and calls that a specific Bot needs.
- What you maintain: review of role policies, VPC placement, egress rules and the evidence that supports periodic access reviews.
- Trust boundary: confirm whether managed and external functions share an execution role, and whether either can reach the PostgreSQL database or Redis cache directly.
- Secret handling: confirm where credentials are read at invocation time and who is allowed to change them.
- Code review: decide how the team reviews code that the integration team writes and what sandboxing it expects for that code.
Ask Medplum to state in writing how each execution path authenticates to the FHIR API, since that answer determines which IAM and network policies you have to write.
The integration team writes the Bot code, tests it and decides how it is named, packaged and released. Under the managed model, Medplum handles more of the packaging. Under the external model, the team chooses its own naming conventions, dependency set, build tooling and test harness, and it owns the results. The decision here is about how much packaging and release work the team wants to carry.
- What you gain: control over naming, packaging, dependencies and build tooling with an external function, or less packaging work with a managed one.
- What you maintain: function code, unit and integration tests, and dependency updates that keep pace with the Bot SDK version in use.
- Test environment: confirm how Bots are invoked in a non-production project and whether a Lambda-specific test harness is needed.
- Release mechanics: decide whether deploys run from CI, how versions are promoted between environments, and how a bad release is rolled back.
- Support load: confirm which runtime versions the team will support and who is on call for failed invocations.
Run one representative Bot through each path in a non-production project before you choose, since timeout, memory and payload behavior should be measured on your own workload before you rely on them.
IAM boundaries and sandboxing for Bot functions
A Bot running on Lambda touches three trust boundaries: the AWS execution role, the Bot's own Medplum identity, and the external systems it calls. The cards below cover what to set at each boundary and what to confirm in the Medplum documentation for your installed version, since the exact sandbox behavior and permission model depend on that release.
Lambda execution role scope
The execution role defines what AWS actions the function can perform, such as reading its own code, writing logs and reaching the database or queues it needs. Start from the smallest policy that lets the function run, then add actions only when a failing test shows they are needed. Review the role whenever a Bot is added, and confirm with Medplum which role the default deployment creates and whether you can replace it with your own.
Self-hosting docsBot identity and access policies
A Bot authenticates to Medplum as its own client identity, so its FHIR reads and writes are limited by the access policies attached to that identity, not by the AWS role. Give each Bot only the resource types and compartments it needs. Check whether your version supports running a Bot as the calling user, since that changes which permissions apply to a given request.
Medplum auth docsSeparate development and production accounts
Keep Bots in a development AWS account and a production AWS account, each with its own Lambda functions, roles, and Medplum project. A bug or leaked credential in development then cannot reach patient data in production. Ask your team how Bot code moves between accounts, whether through CI/CD, and who holds deploy rights in each.
Network placement and egress
Decide whether Bot functions run inside a VPC and which destinations they can reach. Egress to external clinical or payer systems should go through fixed, logged routes, with outbound rules limited to named hosts. Placing functions in a private subnet changes how they reach AWS services and the Medplum server, so test connectivity in a non-production account before you lock the rules down.
Isolation between Bots
Confirm whether each Bot runs in its own Lambda function with separate memory, timeouts, and roles, or whether several Bots share a runtime. Shared runtimes lower cost but widen the blast radius of one faulty or compromised Bot. Verify this behavior for your installed Medplum version before you assume a sandbox boundary exists between Bots.
How secrets reach the function
Credentials for external systems should be read from a managed secret store at runtime, not embedded in Bot code or stored in environment variables where they are visible in the function configuration. Limit the role's read access to the specific secret each Bot needs, and log access to those secrets. Confirm with your Medplum version how project secrets are exposed to a Bot and whether they can be encrypted with a key you control.
Setting up Lambda execution for Bots in a self-hosted install
This sequence takes a self-hosted Medplum team from confirming its installed version and Bot execution settings to a Lambda-backed Bot running in production, with a check at each step so the function, its permissions and its audit trail are verified before any clinical data depends on it.
Confirm the installed version and Bot execution settings
Record the Medplum server version currently running, then compare it with the release notes and the self-hosting documentation for the AWS deployment. Confirm which Bot execution settings your version and deployment method support, including how the server is told to invoke Lambda and which region and account it uses. Check the upgrading guide if you are on an older minor version, because self-hosted Medplum must move through each minor version in sequence. Done when you have a written note of the version, the settings in use and the vendor documentation page you relied on.
Choose the execution model
Decide between Medplum-managed functions, where the platform creates and manages the Lambda functions for each Bot, and external functions, where your team names, builds and deploys the functions with your own tooling. Weigh who maintains deployment code, how quickly you need control over runtime and networking, and how much operational work your platform team can absorb. Record the decision with the reason, since it determines the IAM design and the release process in later steps. Done when the decision and its owner are written down and approved by the team that will run Bots.
Create the AWS account structure and IAM roles
Separate Bot execution from the rest of your workloads, usually with a dedicated account or at least a dedicated set of roles for development and production. Create an execution role for the Lambda functions that grants only the logs and any network or data access each Bot genuinely needs, and a separate role the Medplum server uses to create, update and invoke functions. Keep the server's permissions narrow to the function naming prefix you choose. Verify the policies with the IAM policy simulator and confirm that a test function cannot read resources outside its scope. Done when both roles exist, the simulator results match your intent, and the policy documents are stored in version control.
Configure function naming and the deployment path
Define a naming convention for Lambda functions that makes ownership, environment and Bot identity obvious, and make sure the Medplum server and your deployment tooling use the same prefix. Decide how code reaches AWS: through Medplum-managed deployment from the Bot's stored code, or through your pipeline using the Medplum CLI and AWS tooling. Set the region, memory and timeout values you have confirmed against the documentation, and record them as configuration rather than in individual consoles. Done when a dry run shows the expected function name and configuration for a sample Bot and the naming rule is documented for the team.
Deploy a test Bot and verify invocation
Deploy a simple, non-clinical test Bot in a development project that returns a fixed response and writes nothing to patient data. Invoke it through the Medplum API with a client or user identity that has only the access the test needs. Confirm the response matches the expected output and that the Lambda function was created or updated under the naming rule from the previous step. Done when the invocation succeeds from the intended caller and a failed input produces a clear error rather than a silent result.
Check logs and AuditEvents
Open the CloudWatch log group for the test function and confirm that the execution appears with its request, duration and any error output. Then review the AuditEvent resources Medplum writes for the Bot execution and confirm they identify the Bot, the caller and the outcome. Check that no secret values or patient data appear in logs, and adjust the Bot's logging before going further if they do. Done when you can trace one successful and one failed run from the Medplum record to the Lambda log entry.
Promote the configuration to production
Repeat the deployment through the same pipeline into the production account, using production IAM roles, production secrets handled by your secrets process and the production project. Run the invocation test again with a production-safe identity and confirm alarms or notifications exist for function errors before any real workflow depends on the Bot. Record the production configuration, the owner and the rollback step, which is redeploying the previous Bot version. Done when the production invocation, log entry and AuditEvent are all confirmed and the runbook has been reviewed by the operations owner.
What your team keeps running after go-live
Most of the Lambda work is recurring, and the largest recurring item is keeping the Lambda configuration aligned with the Medplum server. Each Medplum minor and major release can change what the Bot runtime expects, so every upgrade needs a check of the function runtime, execution role, environment variables and the Bot deployment process against the release notes. Follow the upgrade sequence in the Medplum upgrading guide and do not skip minor versions, because a skipped step can leave the Bot layer out of step with the server. Treat the Lambda check as part of the upgrade window, not as a separate task that can drift for months. Confirm with Medplum which runtime and packaging assumptions change in each release before you schedule it.
Function code releases and credential rotation recur on their own schedules and should be owned by named people. Every Bot change that reaches Lambda is a code release, so record which Bot version is deployed to which function and keep a rollback path. Rotate the IAM credentials, access keys and any Medplum client secrets the functions use on a schedule your security team sets, and confirm each rotation reaches every function that depends on it. Review IAM drift at a fixed interval: compare the deployed execution roles and policies against the definitions in your infrastructure code, because manual console edits during incidents are the usual cause of drift that nobody notices until a Bot fails.
Latency needs continuous attention and is hard to fix once users notice it. Track cold starts, timeouts and concurrency limits per function, using the Lambda metrics in your monitoring stack and the timing of Bot executions recorded in Medplum. Set timeouts with headroom above normal execution time, and decide in advance how much concurrency each function may use so that one busy integration cannot starve clinical workflows. Ask your Medplum implementation partner or AWS account team to confirm which limits apply to your account and region, because those values can differ from defaults and change over time.
Limits to confirm before you choose Lambda
Lambda execution for Medplum Bots depends on limits that change with runtime support, AWS account settings and how your deployment is wired. Confirm each item against the Medplum docs and your own AWS account before you commit to a design, because the values that matter are the ones your environment actually receives.
Supported runtimes and Node.js versions
Confirm which AWS Lambda runtimes and Node.js versions the installed Medplum release supports for Bot execution. The Medplum server itself is built on Node.js and TypeScript, but the runtime a Bot executes on is a separate choice that must match the release you run. Check the runtime list in the Medplum docs for your exact version, and plan a runtime upgrade alongside any Medplum server upgrade so Bots do not break at cutover.
Self-hosting docsExecution time and payload size
Confirm the maximum execution time and request or response payload size that apply to Bots on Lambda in your release and in your AWS account. Bots that process large FHIR Bundles, generate PDFs or call slow external systems are the first to hit these ceilings. Test your largest realistic input against the limit, and decide whether heavy work should move to a batch or asynchronous pattern instead.
Concurrency and account quotas
Confirm the Lambda concurrency limits in your AWS account and region, and whether any reserved concurrency is applied to Medplum Bot functions. Bot traffic from Subscriptions, cron schedules and client calls shares these quotas with every other workload in the account. Ask your AWS administrators what quota increases are available and how long they take, and confirm what happens to Bot executions when a limit is reached.
Cold start behavior
Confirm how cold starts affect Bot latency for your workloads, including the first invocation after idle periods and after a new deployment. Latency-sensitive Bots, such as those that answer a clinician-facing request, behave differently from Bots triggered by background Subscriptions. Measure cold and warm invocation times in a non-production project, and decide whether any function needs provisioned capacity, which carries its own cost.
Logging destinations and retention
Confirm where Bot logs are written in your Lambda configuration, which CloudWatch log groups receive them, and how long they are retained. Bot logs can contain identifiers and clinical context, so the destination also determines who can read them and how they reach your audit process. Confirm the logging path for both Medplum-managed and external functions, and check whether AuditEvents and Bot logs cover the same executions.
External function invocation and Beta paths
Confirm whether external functions with your own naming and tooling are invoked the same way as Medplum-managed functions, including how the Bot record points to the function and which IAM role is used. Also confirm which AWS paths are Beta or unsupported in the release you run. The Medplum self-hosting docs mark some non-AWS deployment paths as Beta, so treat any Lambda path not clearly documented as a question for Medplum before you build on it.
Self-hosting docsQuestions teams ask before running Bots on Lambda
What does it cost in effort to run Medplum Bots on Lambda, and who does the work?
The work is mostly one-time setup plus ongoing ownership of the functions, and it is split between your team and whoever builds it. Setup covers choosing between Medplum-managed functions and external functions with your own naming and tooling, defining IAM roles and boundaries, wiring deployment, and testing execution. Your cloud and security teams own the AWS account, IAM approvals and network placement. A partner or your platform engineers typically build the pipeline and runbooks. Recurring effort comes from keeping functions, runtime versions and permissions current after each Medplum upgrade. Ask any quote to separate one-time build effort from retainer or support effort, and to list who is responsible for each item.
How long does a Lambda Bot execution setup take?
Duration depends on scope, mainly the number of Bots, the number of environments, and whether you need external functions with your own tooling. A setup that only runs Medplum-managed functions in one environment is much smaller than one that adds custom naming standards, separate development and production accounts, and formal IAM review. Dependencies on your side also set the pace: AWS account access, security approvals for new roles, and a test project each add waiting time that is outside the build itself. Ask for a written timeline tied to a defined scope, with the approvals and access the plan assumes listed as client dependencies.
What do we need to provide before work starts on Bots and Lambda?
You need to provide access and decisions that the build cannot make alone. The usual list includes a sandbox AWS account with the right to create IAM roles and Lambda functions, a named contact who can approve IAM policies, a non-production Medplum project with representative Bots, and the exact Medplum version your self-hosted deployment runs. The version matters because self-hosted Medplum must be upgraded through each minor version in sequence, and the Lambda approach must match the server you run. Also provide your naming conventions, logging destinations and any rules on which AWS regions or accounts may hold function code.
Can our in-house team run Medplum Bots on Lambda without a partner?
Yes, many in-house teams can, provided they have AWS IAM, Lambda deployment and TypeScript skills, and someone who understands Medplum's Bot execution model and access policies. The harder parts are rarely the first deployment. They are IAM boundaries that stay narrow as Bots grow, test coverage for Bots that touch clinical data, and repeatable deployment across development and production. Teams that already run CI/CD and infrastructure as code usually need less outside help. Teams without a dedicated cloud or security function often use a partner for the initial design and IAM review, then keep the pipeline in-house. Assess your skills against each item in the build sequence before deciding.
What drives the cost of Lambda Bot execution up or down?
The main drivers are the number of Bots, the number of environments, how much custom IAM review you require, and how far CI/CD integration goes. Each additional Bot adds code to test, a role or permission set to review and a deployment path to maintain. Each environment doubles the configuration and secrets handling. Heavier IAM review adds time from security staff, and a full pipeline that promotes Bots from CI into each project adds build and test work. Reuse helps: shared patterns, a standard role template and one deployment pipeline reduce effort as the count grows. Ask any quote to itemize these drivers so you can see which ones you can reduce.
How do we compare Medplum-managed functions with external Lambda functions?
Medplum-managed functions reduce the work of naming, packaging and deploying, but they limit how much you control the function's tooling and IAM setup. External functions let you set your own naming, build tools and IAM boundaries, which suits organizations with established cloud standards, but they add ownership of deployment and permissions. Security reviewers usually want to see the exact role each function assumes and which resources it can reach, so the choice affects review effort. Confirm with Medplum which execution behavior applies to your self-hosted version before choosing, because capabilities differ by release and by how the deployment is configured.
How do we get a quote for running Bots on Lambda?
Start with a written scope that lists the Medplum version, the Bots in scope, the environments, the AWS accounts and regions, whether you need external functions, and the IAM review and CI/CD integration you expect. DeployOpen plans and implements these engagements as fixed-scope work, so scope, deliverables and timelines are agreed in writing before work starts, and a quote follows from that scope. DeployOpen does not publish a price list. Ongoing support, upgrades and testing can be added as a retainer. Share your Medplum version, Bot inventory and AWS constraints to get a scoped proposal.
How DeployOpen scopes and delivers Bot execution on AWS
DeployOpen plans, builds, documents and hands over the Bot execution path for self-hosted Medplum inside your own AWS accounts, including the choice between Medplum-managed functions and external functions. Each engagement starts with a written scope that names the execution model, IAM boundaries and the teams who will operate it.
How we scope
- We confirm which Bots must run on Lambda and which stay on other execution paths.
- We map each Bot's trigger, input, runtime needs and data access before any build starts.
- We agree in writing whether Medplum-managed or external functions fit your naming, tooling and review rules.
How we build
- We configure IAM roles, deployment packaging and network paths in your AWS accounts.
- We wire Bot secrets, logging and error handling so each execution is traceable.
- We test failure paths, timeouts and permission denials before any production traffic reaches the functions.
How we hand over
- We deliver infrastructure code, configuration records and a runbook your team can review and rerun.
- We document IAM boundaries, sandboxing assumptions and the trade-offs behind each execution decision.
- We walk your engineers through deployment, rollback and monitoring so they can operate the setup without us.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer, scoped separately from the build.
- Retainers can cover Medplum version upgrades that change how Bots are packaged or executed.
- Confirm with us during scoping which support responsibilities sit with DeployOpen and which stay with your team.

