Category: Dify on AWS

Hands-on guides to self-hosting, operating and upgrading Dify on AWS, written from production experience.

  • Upgrading Dify in Production: A Checklist for Self-Hosters

    Upgrading Dify in Production: A Checklist for Self-Hosters

    Self-hosting Dify means its release cycle becomes your release cycle. Dify ships often, and most upgrades are uneventful — but the difference between a routine upgrade and an incident is rarely the upgrade itself. It is whether you took a backup you can actually restore, rehearsed the version jump somewhere that is not production, and decided in advance what would make you roll back.

    This article is the checklist I work through when upgrading a production Dify, whether it runs as Docker Compose on one host or as the ECS Fargate architecture from this series. It is written to be printed and ticked off. The ECS and Terraform differences are collected in one section near the end, so the main flow stays the same for everyone.

    Before anything: read the release notes and the upgrade guide

    Reading the release notes before upgrading

    Dify’s own documentation is explicit on this point: choose the target release and read its upgrade guide before you run anything. Some releases are drop-in replacements; others include manual steps — a data migration to run in a particular order, a component that must be upgraded in stages first. The release notes are where that is written down, and they are the only place it is written down.

    • [ ] Target version chosen, and its image tags pinned in your configuration (never latest)
    • [ ] Release notes for the target version read, plus the notes for every version you are skipping over
    • [ ] The release’s upgrade guide read; every manual step copied into your run plan
    • [ ] Plugin compatibility checked — model and tool plugins may need their own updates alongside the core

    Skipping versions deserves one extra sentence: the further you jump, the more the intermediate steps matter. Reading three sets of release notes is tedious, and it is still cheaper than discovering a staged migration halfway through applying it.

    Phase 1: Prepare the ground

    Preparing the ground: window, config backup, secrets
    • [ ] Current version and image tags recorded — your rollback needs to name them exactly
    • [ ] Maintenance window scheduled and announced to users; indexing and scheduled workflows will pause
    • [ ] Configuration backed up: the .env file and the split env files under docker/envs/ copied somewhere safe, outside the host
    • [ ] Secrets inventory confirmed — you know where every value lives (Secrets Manager, in the Terraform setup) and none exists only in a running container

    The configuration backup is the item people skip because it feels like paperwork. It is not: those env files hold your storage settings, your vector store choice and the references to every secret. Lose them in a botched upgrade and you are reconstructing your deployment from memory, under time pressure.

    Phase 2: Back up everything that holds state

    Backing up the database, files and volumes
    • [ ] Database backed up: a snapshot (Aurora, in the managed setup) or a full dump (Compose’s bundled PostgreSQL), taken after the last writes before the window
    • [ ] File storage covered: the S3 bucket has versioning on, or the uploads volume is copied
    • [ ] Named volumes identified — you know exactly which volumes hold state, and you will keep them attached (next phase explains why)
    • [ ] Restore procedure written down, command by command, before the window opens

    An untested backup is not a backup; it is a hope. You do not need to rehearse the full restore before every upgrade — but you do need to have restored successfully at least once, and to know the exact commands. If you have never restored this system, Phase 3 is where that changes.

    Phase 3: Rehearse on staging

    Rehearsing the upgrade on staging
    • [ ] The backup restored onto a staging copy (or a throwaway instance)
    • [ ] The upgrade performed there, start to finish, including every manual step from the release notes
    • [ ] The rehearsal timed — this is how long your production window needs to be
    • [ ] Anything surprising written into the production run plan

    If you have no staging environment, build the rehearsal out of the backup itself: restore it somewhere temporary and upgrade that. A version jump that includes a database migration can fail in ways that only your data triggers — your document sizes, your vector store contents. Rehearsing on empty data proves almost nothing.

    Phase 4: Check the vector store separately

    Checking the vector store as its own upgrade
    • [ ] Vector store’s own upgrade path checked — does this release change, require or stage a vector database upgrade?
    • [ ] If the vector store migrates, its backup taken separately from the main database backup
    • [ ] A post-upgrade indexing test planned (Phase 6) — vector problems hide until something indexes

    The vector store is the component most likely to have an independent migration hiding inside a Dify upgrade. Treat it as a second upgrade nested in the first: its own release notes, its own backup, its own verification.

    Phase 5: Run the upgrade

    Running the upgrade with the same project name
    • [ ] Users notified; window open
    • [ ] New images pulled with pinned tags
    • [ ] Compose run with the same project name and the same options as always — the Dify documentation stresses this, because named volumes attach by project name; a renamed project means fresh, empty volumes and a deployment that looks wiped
    • [ ] API logs watched until database migrations complete
    • [ ] Any staged component steps executed in the order the upgrade guide specifies

    That project-name point is worth the emphasis. The most frightening upgrade failure — Dify comes up empty, no apps, no data — is usually not data loss at all: it is the stack starting against new volumes because the project name or options changed. Keep them identical and the volumes, with all your state, stay attached.

    Phase 6: Re-check plugins and providers

    Re-checking plugins and providers after the upgrade
    • [ ] Plugin list reviewed: every plugin present, enabled and on a compatible version
    • [ ] Each model provider tested with one call — a provider that validated before the upgrade can need re-authorisation after it
    • [ ] Tool integrations spot-checked in one real workflow

    Core upgrades and plugins evolve on separate clocks, and the seam between them is where quiet breakage lives. A companion guide to connecting Dify to Amazon Bedrock — the provider most AWS self-hosters will be re-checking here — is in preparation.

    Phase 7: Smoke tests

    Smoke tests moving from the surface inward
    • [ ] Administrator login works and the console loads
    • [ ] One known workflow runs end to end and returns the expected shape of result
    • [ ] A workflow with a Code node executes (this exercises the sandbox path)
    • [ ] A small document uploads to a knowledge base and finishes indexing (worker, vector store and embedding model in one action)
    • [ ] One published application answers through the service API, not just the console

    Run these in this order: they move from the surface inward, so the first failure tells you roughly which layer to look at. Only when all five pass is the window closed and the upgrade announced as done.

    Rollback: decide the triggers before you start

    Rollback: returning to the previous platform
    • [ ] Rollback defined concretely: previous image tags redeployed, database restored from the Phase 2 backup
    • [ ] Trigger conditions written down: which failures, observed for how long, mean roll back rather than fix forward
    • [ ] One person named as the decision-maker during the window

    Understand what rollback means for a database-backed platform: migrations may be one-way, so rolling back the code usually means restoring the database too — which is why the backup, not the old image tag, is the real rollback. Data written after the upgrade is the price of restoring, and that price is exactly why the trigger conditions belong on paper before the window opens, not in an argument during it.

    The ECS and Terraform variant

    The ECS and Terraform variant of the upgrade

    The checklist is identical; only the mechanics change. On the Fargate architecture, an upgrade is an image-tag change in the task definitions: edit the tags, run terraform plan, and read the diff as your change record before you apply — the plan is where a stray change to an unrelated service shows up while it is still free to fix. The API service runs migrations on boot, so the log-watching step applies unchanged.

    Rollback is correspondingly cleaner: revert to the previous task definition revision, plus the database restore if migrations ran. Aurora’s automated backups and point-in-time recovery make the restore target precise — pick the moment just before the window. Everything above about rehearsal, vector stores and smoke tests applies word for word; managed services remove chores, not decisions.

    Summary

    Upgrade complete: a calmer, higher platform

    Read the target release’s notes and upgrade guide. Back up the database, the files and the configuration — and know the restore commands. Rehearse the jump on a copy of your own data, check the vector store as a separate upgrade, run the upgrade with identical project settings, then verify plugins, providers and five smoke tests before you call it done. Decide the rollback triggers before the window opens. Do those things, and a Dify upgrade goes back to being what it should be: a calendar entry, not an incident.

  • Connecting Dify to Amazon Bedrock: Models, IAM and Region Choices

    Connecting Dify to Amazon Bedrock: Models, IAM and Region Choices

    If you self-host Dify on AWS, Amazon Bedrock is the model provider you will probably reach for first. Your applications stay inside your AWS account, access is governed by IAM rather than by an API key from another vendor, and the usage lands on the same AWS bill as the infrastructure. For client work in Japan there is a second reason: region and data-residency choices are yours to make, not a provider’s.

    The connection is not one switch, though. It is four separate things that each live in a different place: model access in the Bedrock console, a plugin inside Dify, credentials that join the two, and a region decision underneath all of it. This guide walks through them in the order that avoids the common failures. It assumes Dify is already running — if it is not, the architecture I start from is the ECS Fargate setup in this series.

    What you are actually installing

    The Bedrock plugin slotting into Dify

    The connection is a plugin: the official Amazon Bedrock plugin (published by langgenius, Dify’s own developer) from the Dify Marketplace. You are not forking Dify or running a translation proxy — the plugin registers Bedrock as a model provider inside Dify, and your applications call it like any other provider.

    One provider covers three model types: large language models for chat and completion, text-embedding models for knowledge-base indexing, and rerank models for retrieval quality. That breadth is why the setup deserves care. The same configuration will serve your chat applications, decide how every document you index is embedded, and optionally re-order search results — a mistake here is not confined to one app.

    Step 1: Enable model access in the Bedrock console

    Enabling model access in the Bedrock console

    Bedrock models are not switched on by default. In the AWS console, open Amazon Bedrock, go to the model access page, and request access to the models you intend to use. Access is granted per model and per region, so this step comes after you have picked a region (see the region section below) — enabling a model in the wrong region is the single most common reason the later steps appear to fail.

    Model availability varies by region. The catalogue in one region is not the catalogue in another, and the gap is not limited to obscure models: a current chat model may be offered in one region and absent from the next. Decide which models you need first, confirm each one is available in your chosen region, and only then build workflows around them.

    Step 2: Install the plugin in Dify

    Installing the Bedrock plugin from the Marketplace

    In Dify, open the Marketplace, find the Amazon Bedrock plugin by langgenius, and install it. Then go to Settings → Model Provider, select Amazon Bedrock, and open its setup form. That form is where the remaining steps land: it takes a region and a set of credentials, and once it validates, the models you enabled in Step 1 become selectable in your applications.

    Install the plugin before you troubleshoot missing models. A model that is enabled in the console but never appears in Dify is usually a plugin or credentials problem, while a model that appears but errors on use is usually an access or region problem. Keeping that distinction in mind halves the debugging time later.

    Step 3: Credentials — access key or IAM role

    Two credential paths: access key or IAM role

    The plugin supports two authentication paths. The first is the familiar one: an AWS access key and secret key, with an optional session token if you are using temporary credentials. The second is IAM role authentication, where the plugin obtains credentials from the environment Dify runs in and refreshes them on every invocation, so nothing long-lived is stored at all.

    The access key path works anywhere — a laptop trial, a single EC2 instance — and that convenience is its whole case. Its cost is a long-lived secret sitting in Dify’s configuration, which you then have to protect, rotate and eventually revoke. Treat it as a starting point for evaluation, not as the production answer.

    On ECS Fargate, prefer the IAM role. Give the Dify services a task role with permission to use Bedrock, and the plugin picks those credentials up automatically — there are no keys in Dify to leak, rotate or forget. This is how the Terraform architecture in this series is wired: the task role is the credential. Whichever path you choose, use separate identities for development and production, so a key or role used in a sandbox cannot reach client data.

    Step 4: Assign models to chat, embedding and rerank

    Assigning models to chat, embedding and rerank

    With the provider saved, assign a default model for each role your workspace uses. The chat model is the visible choice — it is what your applications think with — and several model families are available on Bedrock, each with different strengths, context sizes and prices. Pick per application where it matters rather than forcing one model on everything.

    The embedding model deserves more deliberation than it usually gets. Every document in every knowledge base is embedded with the model you choose here, and changing the embedding model later means re-indexing those knowledge bases to match. Choose it deliberately at the start, and treat a later change as a small migration project, not a settings tweak. Rerank is the optional third role: a rerank model re-orders retrieved passages before they reach the chat model, and it is a cheap quality win for knowledge-base applications once the basics work.

    Step 5: Make a test call before you build anything

    Making a test call to validate the connection

    Before building a real application, run the smallest possible test: a one-prompt chat application using your new provider, or the test facility in the model provider settings if your version offers one. A successful call validates model access, credentials and region in a single stroke. A failure at this stage is cheap; the same failure discovered after you have built a workflow is not.

    Follow it with a second, smaller test that people skip: create a test knowledge base, upload one short document, and confirm indexing completes. That exercises the embedding path end to end — Dify, the plugin, Bedrock and your vector store — and indexing failures otherwise surface days later, in front of users.

    Choosing a region, and cross-region inference

    Region choice and cross-region inference, Japan highlighted

    Your Bedrock region does not have to be the region Dify runs in, but it usually should be: every prompt crosses between them, and distance adds latency to every call. The stronger forces are availability and residency. As noted above, the model catalogue differs by region, so the region decision and the model decision are really one decision — make them together, and write the outcome down, because changing region later changes the model identifiers your applications reference.

    Bedrock also offers cross-region inference profiles, which route a request across several regions behind one identifier to improve throughput and availability. For Japanese client work the important variant is the Japan inference profile, which keeps routing within Japan. If a client’s data may not leave the country, that profile is how you use Bedrock’s managed routing without giving up residency — confirm the profile covers the models you enabled before you rely on it.

    Least-privilege IAM, in practice

    Least-privilege IAM: only the keys you need

    Whichever identity you use — IAM user for keys, task role on Fargate — it needs permission to invoke the models you enabled, in the regions you use, and nothing else. It does not need administrator access, it does not need other AWS services, and it does not need models you have not enabled. Scope the policy to those models, and widen it deliberately, one model at a time, as you enable more.

    Two habits make this sustainable. First, keep development and production identities separate, so experiments never hold production permissions. Second, review the policy whenever you enable a new model or region; permission drift in both directions — too broad, and silently stale — tends to accumulate exactly at those moments.

    What it costs

    Pay-per-token cost of Bedrock models

    Bedrock is pay-per-token: you pay for input and output tokens on language models, and for input tokens on embedding, with no hourly charge for the connection itself and no fee for the Dify plugin. The practical consequence is the one noted in the flagship architecture guide: for a busy team, model usage will exceed the infrastructure bill. The Dify platform might cost the price of a team lunch per month; the models it calls are the real spend.

    Budget accordingly. Put a billing alarm on the AWS account, watch usage per application once you have real traffic, and remember that embedding a large knowledge base is a one-off token cost that can surprise you if you index first and count later.

    Troubleshooting

    Troubleshooting the Bedrock connection

    The model does not appear in Dify. Check, in order: the plugin is installed; the credentials validate; and model access is enabled for that model in the region configured in the provider. Most cases are the third one, in a different region than the one you checked.

    Access denied when the model is called. The identity lacks permission to invoke that model, or access is still pending. Compare the model and region in the error against the console’s model access page, then against your IAM policy’s scope.

    A model is enabled but invocation asks for an inference profile. Some models can only be invoked through a cross-region inference profile rather than by their bare model ID. Select the profile — for Japan-residency requirements, the Japan profile — in place of the direct model where the plugin offers the choice.

    It works in the Bedrock playground but not in Dify. The playground uses your console identity; Dify uses the credentials or role you configured. The two are different identities, possibly in different accounts — check the Dify-side identity first.

    Summary

    Bedrock connected and glowing steadily

    Connect in this order and the pieces stay separable: choose a region, enable model access there, install the official plugin, authenticate with an IAM role wherever Dify runs on AWS (task role on Fargate, keys only for trials), assign chat, embedding and rerank models deliberately, and test both a chat call and a document index before building anything real. Do that, and Bedrock becomes the least interesting part of your Dify stack — which is exactly what infrastructure should be.

    If your Dify is not on AWS yet, start with Self-Host Dify on AWS with Terraform. A companion checklist for upgrading Dify in production is in preparation.

  • What Dify on AWS Actually Costs: Three Architectures Compared

    What Dify on AWS Actually Costs: Three Architectures Compared

    “How much does it cost to run Dify on AWS?” has no single answer, because Dify on AWS is not one architecture. The same application runs on a single virtual server for the price of a streaming subscription, or as a managed, highly available platform for roughly ten times that. This article prices the three setups I actually recommend to people, side by side, so you can choose with your eyes open.

    Every figure below is an estimate for the Tokyo region (ap-northeast-1) as of December 2026, based on public AWS list prices, and labelled as an estimate on purpose: prices change, discounts and free tiers vary, and your usage will differ. Verify the current numbers on the official AWS pricing pages before you budget. Model API usage is excluded from every total here — it is billed per token by Bedrock or your chosen provider, and for a busy team it will exceed the infrastructure bill. That is normal, and it is the same for all three setups.

    The three setups at a glance

    The three architectures side by side
    1. All-in-one EC22. Lean containers3. Fargate production
    ShapeOne EC2 instance, Docker ComposeSmall ECS Fargate tasks + Aurora Serverless v2ECS Fargate + Aurora + ElastiCache, Terraform-managed
    Infrastructure estimateUSD 25–50 / monthUSD 70–115 / monthUSD 120–200 / month
    AvailabilitySingle host; downtime on failure or patchingManaged database; tasks restart automaticallyManaged data tier, rolling deploys, multi-service scaling
    Operating effortAll yours: patching, backups, upgradesLow to moderateLow; infrastructure as code
    Best forPersonal use, small teams, trialsSmall production services on a budgetClient-facing and team-critical deployments

    The rest of this article explains what is inside each number, what drives it up, and where the traps are. The pattern to notice: the differences are rarely the compute. They are the always-on managed services around it.

    Setup 1: all-in-one EC2

    All-in-one EC2: everything on one instance

    One EC2 instance meeting Dify’s documented minimum (at least 2 cores and 4 GiB of RAM; 8 GiB is more comfortable) runs the entire Compose stack — application, PostgreSQL, Redis and vector store on one host and one disk. The estimated USD 25–50 per month covers the instance and its SSD storage in the Tokyo region; there is no load balancer, no NAT gateway and no managed database adding fixed charges.

    This is the cheapest way to keep Dify running continuously, and the estimate is genuinely achievable — as long as you respect what the price buys. One host means one point of failure, backups and patching are your job, and scaling means a maintenance window and a bigger box. My step-by-step guide to this setup (in preparation) covers the hardening that makes it production-viable: closed security groups, HTTPS, replaced default secrets and tested backups.

    Setup 2: lean containers

    Lean containers with a managed database

    The middle option keeps the application in containers and moves only the database to a managed service. Dify’s services run as small ECS Fargate tasks at modest CPU and memory settings, and Aurora PostgreSQL Serverless v2 holds the data; Redis and the vector store stay as containers, and the design deliberately omits the NAT gateway — tasks run with public IPs in public subnets, or reach AWS services through VPC endpoints instead.

    The estimated USD 70–115 per month breaks down roughly as: Aurora Serverless v2 at its 0.5 ACU minimum, an estimated USD 44–55 (Tokyo prices ACU-hours higher than US regions — USD 0.15 versus USD 0.12 per ACU-hour); the small Fargate tasks making up most of the remainder; and no NAT gateway charge, which alone saves an estimated USD 32 or more per month against the full production design. The honest trade-offs: tasks in public subnets need careful security-group discipline, some AWS services still require internet egress, and a load balancer — if you add one for HTTPS convenience — adds an estimated USD 16–25 per month and pushes you toward the top of the range.

    Choose this tier when a real service depends on Dify but the budget is firm. You get a managed, backed-up database and self-healing containers, and you accept a less standard network design in exchange for deleting the fixed charges.

    Setup 3: the Fargate production architecture

    The full Fargate production architecture

    The third setup is the architecture from my guide to self-hosting Dify on AWS with Terraform: every Dify service as its own Fargate service, Aurora PostgreSQL Serverless v2 for data, ElastiCache for Redis, S3 for files, an Application Load Balancer in front, and secrets in Secrets Manager. Its always-on floor is an estimated USD 120–200 per month before any real traffic.

    The components explain the floor: Aurora at its 0.5 ACU minimum is an estimated USD 44–55 of it, the ALB an estimated USD 16–25, one NAT gateway an estimated USD 32 plus data processing, ElastiCache’s smallest node roughly USD 12–25, and the minimum-size Fargate services (API, worker and web running continuously) the remainder. Nothing in that list is waste — each line buys backups, failover or a deploy that does not take the service down. You are paying, roughly, the price of one good team lunch per month to not be your own database administrator, patcher and backup system.

    What actually drives the bill

    The fixed charges that drive the bill

    Four fixed charges decide which tier you land in, and none of them is the Dify application itself. The NAT gateway is the classic surprise: it bills by the hour whether or not traffic flows, so a design with one per availability zone multiplies a charge most small deployments can reduce to one — or design away entirely, as the lean setup does. The load balancer is the second fixed line, justified by HTTPS termination and rolling deploys, optional only in the leanest designs.

    Aurora Serverless v2’s minimum capacity is the third: at 0.5 ACU the database has an hourly floor even when idle, and Tokyo’s per-ACU-hour price is higher than US regions’. The fourth driver is not fixed at all — it is model usage. Every chat response, embedding and rerank is billed per token by your model provider, and an active team’s model bill routinely passes its infrastructure bill. Budget for the two separately, and put alarms on both.

    Cost traps that surprise people

    Cost traps: forgotten stacks and quiet charges

    The first trap is leaving test deployments running. A forgotten Fargate stack or EC2 instance bills quietly for months; tag everything, and delete trials with the same Terraform destroy or console pass that created them. The second is data transfer and NAT data processing on a busy indexing workload — small per gigabyte, but knowledge-base ingestion is exactly the workload that moves gigabytes.

    The third trap is assuming the minimum configuration stays the minimum. Aurora scales up under load and bills for the capacity used; worker tasks scale with indexing queues; storage grows with every uploaded document. The estimates here are floors for quiet deployments, and a popular deployment should expect to sit above them. Set a billing alarm at the level that would surprise you, not the level that would bankrupt you — you want the email while the number is still interesting, not catastrophic.

    Which one should you choose?

    Three paths to three architectures

    Choose EC2 if the audience is you and a few teammates, downtime is an inconvenience rather than an incident, and the budget matters more than the operating time. Choose lean containers if a service depends on Dify daily, the database is the part you least want to operate yourself, and you can accept a less conventional network layout to keep fixed costs down. Choose the full Fargate architecture if clients or a whole team depend on it, if you need deploys without downtime, or if your time is worth more than the difference — which, at these numbers, it usually is.

    And in all three cases, remember the excluded line: pick your model provider and estimate token usage separately. A guide to connecting Dify to Amazon Bedrock as the model provider is coming in this series (in preparation), including the region and pricing considerations on the AWS side.

    Summary

    Comparing the three monthly costs

    Dify on AWS costs an estimated USD 25–50 per month on a single EC2 instance, USD 70–115 as lean containers with a managed database, and USD 120–200 as the full Fargate production architecture — Tokyo region, December 2026, infrastructure only, every figure an estimate to verify against current AWS pricing. The spread is not about the application; it is about how much availability, automation and operational relief you buy around it. Decide which of those you actually need, and the right tier chooses itself.

    Coming next in this series (in preparation): Dify on EC2 with Docker Compose — the cheapest production-viable setup; and a guide to connecting Dify to Amazon Bedrock as your model provider.

  • Dify on EC2 with Docker Compose: The Cheapest Production-Viable Setup

    Dify on EC2 with Docker Compose: The Cheapest Production-Viable Setup

    Not every Dify deployment needs load balancers, managed databases and a Terraform repository. If you are running Dify for yourself or a small team, the cheapest setup that is still honest to call “production” is a single EC2 instance running the official Docker Compose stack — hardened, backed up, and served over HTTPS. This guide walks through that setup and is clear about where its limits are.

    I run Dify on AWS for client work in Japan, and I still keep a personal instance on EC2. It costs less per month than the managed architecture in my ECS Fargate guide, and for a handful of users the difference in reliability does not matter. What does matter is doing the small number of things that separate a demo from a deployment: replacing the default secrets, closing the network, and having backups you have actually tested.

    A note on versions: this guide follows the official Dify documentation as of December 2026. The Compose deployment requires Docker Compose 2.35.0 or later, and the documented minimum hardware is 2 CPU cores and 4 GiB of RAM. Dify releases move quickly, so check the current documentation and the files under docker/ in the Dify repository before you deploy.

    What you will have at the end

    The finished single-instance Dify setup
    • One EC2 instance running the full Dify Compose stack (API, worker, web, PostgreSQL, Redis, vector store and the rest) behind a reverse proxy
    • HTTPS on your own domain, with only ports 80 and 443 reachable from the internet
    • Every bundled default secret replaced with a real one
    • Automated backups: EBS snapshots for the instance and a scheduled database dump you can restore from
    • A clear picture of what this setup cannot do, and when to move off it

    Who this setup is for

    Who the EC2 setup suits: solo developers and small teams

    This is the right shape for a personal instance, a small internal tool for a team of two to ten people, or a serious evaluation you expect to run for months. Traffic is modest, uptime expectations are human (“fix it tomorrow” is acceptable), and one person operates everything. In that world, a single well-kept instance beats a distributed system you have to babysit.

    It is the wrong shape for a client-facing service with an uptime promise, for heavy document indexing, or for anything where an hour of downtime becomes a business problem. A single instance is a single point of failure, and no amount of hardening changes that. If that is your situation, skip ahead to the ECS Fargate architecture instead of growing this one past its limits.

    Choosing the instance

    Three instance sizes, the middle one recommended

    Start from the documented minimum: at least 2 cores and 4 GiB of RAM. That minimum does run Dify, but the Compose stack starts well over a dozen containers, and document indexing plus a code sandbox compete for the same memory. In practice, treat 4 GiB as the floor for a trial and 8 GiB as the comfortable size for an instance you intend to keep.

    For storage, a general-purpose SSD volume in the 30–50 GB range is a sensible starting point for the operating system, the Docker images and the bundled databases. Knowledge-base documents and uploads live on this disk in the default Compose configuration, so size it for your content, not just the software. If the knowledge base grows large, that growth is one of the signals to move storage — and eventually the whole deployment — to managed services.

    On cost: a single instance of this size, with its storage, is an estimated USD 25–50 per month in the Tokyo region as of December 2026. Treat that as a planning estimate, not a quote — check the current EC2 pricing page for your instance type and region before you budget. Model API usage, if you call Bedrock or another provider, is billed separately and can exceed the instance cost for a busy deployment.

    Locking down the network

    A firewall in front of the server with only web ports open

    The security group is your firewall, and the rule is simple: the internet may reach ports 80 and 443, and nothing else. Port 80 exists so the reverse proxy can redirect to HTTPS and answer certificate challenges; all real traffic belongs on 443. The database, Redis and every other container port stay closed — the Compose stack’s data services have no reason to be reachable from outside the host.

    SSH needs the same discipline. Restrict port 22 to your own IP address, or better, avoid opening it at all and use AWS Systems Manager Session Manager to reach the instance through the console or CLI. Either way, “open to the world for convenience” is how small instances get compromised, and a Dify host holds your model provider keys.

    One more network note: Dify’s first-run setup screen creates the initial administrator account, and until you complete it, anyone who can reach the address can claim it. Do the initial setup immediately after the stack starts, before you announce the address to anyone — or keep the security group closed to your IP only until the admin account exists.

    Installing Dify with Docker Compose

    Installing Dify from its Docker Compose stack

    The deployment itself follows the official quick start. Install Docker Engine and Docker Compose (2.35.0 or later) on the instance, clone the Dify repository, and work in its docker/ directory. Before starting anything, copy the example environment file to .env and work through the secrets checklist in the next section — the order matters, because the database initialises with the password it finds on first boot.

    Start the stack with docker compose up -d, using the default profile unless you know you need the optional services. Then open the install page at http://your-domain/install (through the proxy, this becomes your HTTPS address) and create the administrator account. After that, sign in and confirm the console loads, the worker is running, and a small test workflow executes.

    Two operational habits are worth forming on day one. First, pin your deployment: note the Dify version you installed, and upgrade deliberately rather than pulling the latest images by reflex. Second, keep a copy of your .env file somewhere safe and private — losing it means losing the values that encrypt and sign parts of your deployment’s data.

    HTTPS with a reverse proxy

    HTTPS termination at a reverse proxy

    Dify’s Compose stack serves plain HTTP through its bundled nginx on port 80 by default (the EXPOSE_NGINX_PORT setting controls the published port). For a real deployment, put a reverse proxy in front that terminates TLS: a common pattern on a single instance is a lightweight proxy with automatic Let’s Encrypt certificates, or nginx configured with certificates you manage. The proxy listens on 443, forwards to the Compose nginx, and redirects port 80 traffic to HTTPS.

    Whichever proxy you choose, set Dify’s console, service API and web app base URLs to your HTTPS domain afterwards. If you skip this, share links, file URLs and OAuth callbacks will quietly point at the wrong address or scheme. Test one full round trip — sign in, upload a file, open a published app link — before calling the setup done.

    The secrets checklist

    The default secrets that must be replaced

    The Compose files ship with development credentials so the demo starts in one command, and every one of them is public knowledge. Replacing all of them is the single most important step in this guide. The official documentation lists what to change in docker/.env before other people can reach the deployment:

    • Database and Redis: set DB_PASSWORD and REDIS_PASSWORD to strong, unique values.
    • Code sandbox: set SANDBOX_API_KEY and CODE_EXECUTION_API_KEY to the same strong secret.
    • Weaviate: set WEAVIATE_API_KEY to a strong secret listed in WEAVIATE_AUTHENTICATION_APIKEY_ALLOWED_KEYS, and set WEAVIATE_AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED=false so the vector store requires authentication.
    • Plugin daemon: set PLUGIN_DAEMON_KEY and PLUGIN_DIFY_INNER_API_KEY to separate strong values.
    • Agent tokens: replace the bundled agent API token and generate the agent server secret key in its required format, keeping the local sandbox auth token generated at startup.

    Apply changes by restarting the stack so the new values take effect. One exception deserves care: the database password. Once the database has been initialised, change the password on the database server first and only then update DB_PASSWORD to match — changing only the .env file locks the application out of its own database.

    Also note the default stack’s quiet strength: it publishes no host ports for the database, Redis, the sandbox or Weaviate. Keep it that way. Restrict access to those services on the private network too, not just at the security group.

    Backups that actually exist

    Snapshots and database backups with a restore path

    Two layers cover a single-instance deployment. EBS snapshots — scheduled automatically with AWS Backup or a lifecycle policy — capture the whole volume, including Docker’s data. Separately, schedule a regular pg_dump of the Dify database to a file that is copied off the instance, for example to an S3 bucket, so a lost instance does not take the only copy with it.

    The rule from my managed-architecture guide applies unchanged: a backup you have never restored is a hope, not a backup. In the first month, restore a snapshot to a throwaway instance (or at least restore the database dump into a scratch container) and confirm Dify starts and your apps are present. The twenty minutes that takes is the cheapest insurance in this entire setup.

    The honest limits

    The honest limits of a single instance

    Availability is the obvious one: patching, a failed upgrade or an instance problem means downtime, because there is nothing else to serve traffic. Scaling is the second: when indexing or concurrent users outgrow the box, your only move is a bigger instance and a maintenance window. Neither is a defect — they are the price of the cheapest tier, and they are acceptable exactly as long as the audience is small and forgiving.

    Upgrades are manual work here, too. Read the target release’s upgrade guide first, and run every Compose command with the same project name and options as your original deployment, so the named volumes stay attached and the same configuration is loaded. A full walkthrough of upgrading safely is coming in a companion article (in preparation); the short version is: back up, read the guide, then upgrade — never in another order.

    When to graduate to ECS Fargate

    Graduating from one instance to orchestrated containers

    Move when any of these become true: the instance serves people outside your own team, downtime starts costing money or trust, indexing load makes the console sluggish, or you are avoiding upgrades because they feel risky. Those are signs the operational work has outgrown the savings. My guide to self-hosting Dify on AWS with Terraform builds the managed version — ECS Fargate for the services, Aurora PostgreSQL and ElastiCache for the data, S3 for files — and most of what you learned here transfers: the secrets discipline, the settings that matter, and the backup habit.

    Summary

    A calm, low-cost Dify instance at sunrise

    A single EC2 instance running the official Compose stack is the cheapest Dify deployment worth calling production: 2 cores and 4 GiB at minimum, a security group that exposes only 80 and 443, a reverse proxy for HTTPS, every default secret replaced, and snapshots plus database dumps you have test-restored. It will not scale and it will not survive its own host — and for a personal instance or a small team, it does not need to. When it does, the Fargate architecture is the next step, not a bigger box.

    Coming next in this series (in preparation): What Dify on AWS Actually Costs, a three-architecture comparison; and a guide to connecting Dify to Amazon Bedrock as your model provider.

  • Self-Host Dify on AWS with Terraform: ECS Fargate, Aurora PostgreSQL and ElastiCache

    Self-Host Dify on AWS with Terraform: ECS Fargate, Aurora PostgreSQL and ElastiCache

    Dify’s own quick start is one command: clone the repository, run Docker Compose, open your browser. That gets you a demo in ten minutes — and a stack you cannot safely leave running for a real team. The Compose file runs about fifteen containers on one host, including PostgreSQL, Redis and the vector database, all with bundled default secrets, all gone if the host dies.

    This guide builds the version I would actually hand to a client: Dify’s containers on ECS Fargate, its data in managed services (Aurora PostgreSQL, ElastiCache for Redis, S3 for files), everything defined in Terraform, with the decisions — and the bill — explained. I build and operate Dify on AWS for client work in Japan; this is the architecture I start from, and the notes include the parts that only show up after you have run it for a while.

    A note on versions: Dify moves fast. This guide is written against the Dify 1.x line (the official Compose file referenced image tag 1.20.0 when this was written, in December 2026). The architecture does not depend on the minor version; the environment settings occasionally do, so check the current files under docker/envs/ in the Dify repository before you deploy — recent versions reorganised them.

    What you will have at the end

    Laptop showing the finished Dify web console and dashboard
    • Dify’s web console and API behind an Application Load Balancer with HTTPS, on your own domain
    • The Dify services (api, api_websocket, worker, worker_beat, web, plugin_daemon, sandbox) running as Fargate tasks you can scale independently
    • Aurora PostgreSQL Serverless v2 holding Dify’s application data, with automated backups and point-in-time recovery
    • ElastiCache for Redis as the Celery broker and cache
    • Uploaded files and knowledge-base documents in S3 instead of a container filesystem
    • All secrets in AWS Secrets Manager, none in the repository
    • The whole thing reproducible from Terraform: one apply to build, one destroy to remove

    Why ECS Fargate (and when not to)

    Diagram comparing AWS container options: EC2, ECS Fargate and EKS

    Three container options are realistic on AWS, and the honest comparison is short.

    EC2 with Docker Compose is the cheapest way to run Dify and the closest to the official guide. It is the right answer for a personal instance or a trial. Its limits are operational: one host is one point of failure, patching and backups are yours, and scaling means a bigger box.

    ECS Fargate is the middle path this guide takes. No hosts to patch, each Dify service scales on its own, rolling deploys are built in, and the data tier moves to managed services where AWS handles backups and failover. You pay more than for a single EC2 instance; you buy back the operational work.

    EKS only earns its complexity if your organisation already runs Kubernetes and wants Dify inside it. If you have to ask whether you need EKS for Dify, you do not.

    The architecture, service by service

    Dify is not one application. Its Compose stack has three groups, and the AWS design follows from keeping them straight.

    Diagram of the Dify on AWS architecture: an Application Load Balancer in front of ECS Fargate services (web, api, api_websocket, worker, worker_beat, plugin_daemon, sandbox, Weaviate), backed by Aurora PostgreSQL, ElastiCache Redis and S3, with Secrets Manager, CloudWatch and Terraform as platform services.

    Stateless Dify services — these become Fargate services, one task definition per role, sharing the same images as the Compose stack: api (the backend and console API), api_websocket (live workflow co-editing; an optional service enabled by the “collaboration” Compose profile), worker (Celery: document indexing, workflow jobs), worker_beat (the scheduler), web (the Next.js frontend), plugin_daemon (model and tool plugins), and sandbox (isolated execution for Code nodes). The sandbox deserves one caution: it runs user code, so it belongs in its own service with no route to anything except the API that calls it — do not co-locate it with the API task to save money.

    Stateful dependencies — these leave the containers entirely. PostgreSQL becomes Aurora PostgreSQL Serverless v2 (Dify points at it with its normal DB settings). Redis becomes ElastiCache. File storage switches to S3 by setting Dify’s storage type to S3, so uploads and dataset files survive task replacement. The bundled Weaviate is the one dependency I usually keep as a container at first — a small dedicated Fargate service with EFS for its data — and move to a managed or external vector store only when the knowledge base grows; Dify also supports external vector databases through its VECTOR_STORE setting if you already run one.

    Edge and platform — an ALB terminates HTTPS (ACM certificate) and routes console traffic to web and API paths to api. nginx, which fronts everything in the Compose stack, is no longer needed as a separate container; the ALB does its job. Secrets (database password, Redis auth, Dify’s SECRET_KEY, the sandbox and plugin-daemon keys) live in Secrets Manager and are injected into tasks. Logs go to CloudWatch Logs, one log group per service — when a workflow fails at 2 a.m., this is where you will live.

    Networking follows the standard shape: public subnets only for the ALB, private subnets for tasks and data, and VPC endpoints (or a NAT gateway) for tasks to reach ECR, S3 and Secrets Manager. Budget note: a NAT gateway in every availability zone is a quiet, fixed monthly cost that surprises people; a single NAT for a small deployment, plus gateway endpoints for S3 and DynamoDB (which are free), is a reasonable economy — with the availability trade-off stated, not hidden.

    The Terraform layout

    Cloud infrastructure being built from Terraform modules

    Keep it boring. One root module per environment, composed from small modules you will reuse for the next service you host:

    • network: VPC, subnets, endpoints, security groups (one per tier, chained by reference, no open database ports)
    • data: Aurora cluster (Serverless v2 scaling block, minimum 0.5 ACU), ElastiCache replication group, S3 bucket with versioning and encryption, EFS for Weaviate
    • platform: ECS cluster, task definitions and services per Dify role, ALB and listeners, ACM certificate, Secrets Manager entries, CloudWatch log groups and alarms
    • state: an S3 backend with DynamoDB locking, created once by hand (or by a bootstrap stack) before the first apply

    Two practices matter more than the module structure. First, pin everything: the Terraform AWS provider, and the Dify image tags — never deploy latest for a platform whose upgrades occasionally include manual data steps (Dify’s 1.17 line, for example, required a staged Weaviate upgrade; a pinned tag is what turns that from an incident into a planned change). Second, treat the Dify environment variables as code: define them in the task definitions from variables and secrets, so a diff shows exactly what a deploy changes.

    The Dify settings that actually matter

    Dify settings panel with a key and configuration toggles

    Most of Dify’s .env transfers directly to task environment variables. The ones people get wrong:

    • SECRET_KEY: generate a real random value, store it in Secrets Manager, and never change it casually — it signs sessions and encrypts stored credentials.
    • Database and Redis settings: point them at Aurora and ElastiCache endpoints, with TLS where the service requires it, and use a dedicated database and user for Dify.
    • Storage: switch the storage backend from local disk to S3 (the storage settings live in the env files) and give the task role permission to exactly one bucket. Leaving local storage on Fargate means uploads vanish on the next deploy.
    • Sandbox keys: the sandbox API key and the code-execution endpoint key must match between the api and sandbox services, and neither may be the bundled default. The same applies to the plugin daemon key. Every default secret in the Compose files is publicly known; replacing all of them is the single most important security step in this whole guide.
    • Web and console URLs: set Dify’s console, service API and web app base URLs to your HTTPS domain, or share links and OAuth callbacks will quietly point at the wrong place.

    Deploying, in order

    Stairs leading up to a cloud, showing the deployment steps in order
    1. Apply the network and data modules first, and note the endpoints Terraform outputs.
    2. Set the secret values in Secrets Manager (Terraform creates the entries; the values themselves are set out of band so they never touch state in plain text).
    3. Apply the platform module. The first run pulls images and starts services; the api service runs database migrations on boot.
    4. Watch the api service’s logs until migrations complete, then open the ALB address: Dify’s setup screen creates the first administrator account. Create it immediately — until you do, anyone who can reach the address can.
    5. Point your domain’s DNS at the ALB, confirm HTTPS, and only then open the security groups to your team’s addresses (or your VPN) if the console is not meant to be public.

    First-boot checks that catch most problems: the worker service’s logs show it connecting to Redis and registering tasks; uploading a small document to a new knowledge base completes indexing (this exercises worker, S3, the vector store and your model provider key in one action); and a test workflow with a Code node returns a result (this exercises the sandbox path).

    What it costs

    Balance scale weighing cloud infrastructure against coins

    Estimates, not quotes — AWS prices change and vary by region, so treat these as planning figures for a small production deployment in a major region (US East or Tokyo), checked against public AWS pricing in late 2026, and re-check the official pricing pages before you budget.

    The always-on floor is roughly USD 120–200 per month before any real traffic: Aurora Serverless v2 at its 0.5 ACU minimum is about USD 44–55 of that (Tokyo is priced higher per ACU-hour than US regions), the ALB about USD 16–25, one NAT gateway about USD 32 plus data processing, ElastiCache’s smallest cache node roughly USD 12–25, and the Fargate services at minimum size (api, worker and web running continuously at small CPU/memory settings) the remainder. Model API usage (Bedrock or otherwise) is billed separately and, for a busy team, will exceed the infrastructure bill — that is normal, and a later article in this series will compare this architecture’s cost side by side with the EC2 and minimum setups.

    The honest summary: you pay roughly the price of one good team lunch per month to not be your own database administrator, patcher and backup system. For a client-facing deployment that trade is easy; for a personal playground it is not — a single EC2 instance is the better fit.

    Running it: the short list

    Monitoring gauges with a heartbeat line for running Dify
    • Backups: Aurora’s automated backups with point-in-time recovery cover the database; the S3 bucket’s versioning covers files. Test a restore once, in the first month, or you do not have backups — you have a hope.
    • Alarms: alarm on worker queue depth (indexing silently backing up is the most common Dify production complaint), api 5xx at the ALB, and Aurora CPU/ACU saturation.
    • Scaling: worker is the service that scales with document and workflow load; api scales with console and API traffic; web barely moves. Scale them independently — that was the point of splitting them.
    • Upgrades: read the release notes, snapshot first, upgrade in a maintenance window, and check whether the vector store has its own migration step before you touch the Dify version. A later article in this series will set out the full procedure as a production upgrade checklist.

    Failure modes worth knowing in advance

    Magnifying glass inspecting a failed link in a service chain
    • Indexing stuck at “indexing” forever: almost always the worker cannot reach Redis, the vector store, or the model provider — in that order. Check worker logs before touching anything else.
    • Code nodes timing out: the api cannot reach the sandbox service, or the sandbox keys do not match between services.
    • Sessions dropping after a deploy: SECRET_KEY differs between api tasks or changed between versions.
    • Uploads disappearing: storage is still on local disk in a task somewhere — check the storage setting on every service that writes files, not just api.

    Summary

    Sunrise over the cloud setup with a checkmark

    Run Dify’s services as services, and its data as managed data. ECS Fargate for the containers, Aurora PostgreSQL and ElastiCache for the state Dify cannot afford to lose, S3 for files, Secrets Manager for the keys, Terraform for all of it — pinned, diffed and reproducible. The Compose stack is a brilliant demo and a fine personal setup; this is what it grows into when a team depends on it.

    Coming next in this series (in preparation): Dify on EC2 with Docker Compose — the cheapest production-viable setup; What Dify on AWS Actually Costs, a three-architecture comparison; and a guide to connecting Dify to Amazon Bedrock as your model provider.