A step-by-step guide to recreating Railway production, staging and pull request environments on AWS: how isolation and variables map, where AWS accounts and clusters fit, and a TypeScript version where environments come from one codebase.

Railway environments are one of its better ideas: every project starts with production, you add a persistent staging environment, and pull requests get temporary environments that are deleted when the pull request is merged or closed. Duplicating an environment copies its services, variables and configuration.
On AWS the same structure takes decisions about accounts, networking and who can reach what. This guide maps each Railway environment type to AWS and then shows the environments created from one codebase.
The Railway behavior is from its environments documentation, checked on November 23, 2026. For the AWS side, AWS Organizations describes the multi-account structure commonly used to keep environments apart.
For every Railway environment list the services it runs, the variables that differ from production, the domains attached and the data it holds. Staging usually has its own database with test data and its own third-party keys, such as a Stripe test key, and those differences are the part that is easiest to lose in a move, since on Railway they were a few variables in a dashboard. Note which variables are shared across environments, because shared values need a decision on AWS about whether each environment gets its own copy.
The most common layout is one AWS account for production and one for everything else, which keeps a staging mistake out of production at the account boundary. Inside an account, an environment is a VPC with its subnets, an ECS cluster, an RDS instance and a load balancer, all of which need to exist before the first deploy. Smaller teams sometimes run staging as a second set of services in the production VPC, which saves money and weakens the isolation Railway gave you for free, so write the IAM rules that keep staging services from reading production secrets before you start.
The pull request environments are the part to decide last, because they are the most work to rebuild by hand and the least important for cutting over. Keep Railway's PR environments running for a while if they are still useful, and move production and staging first.
Encore brings infrastructure from code, and an environment is a deploy target for the same code, not a second copy of the infrastructure to maintain. Per the environments docs, each environment is isolated, automatically provisioned and kept in sync with the codebase, and you create one in the Platform Dashboard by choosing a name, a type (production or development), a deploy trigger such as a branch, and a cloud provider. For a production environment in your own AWS account, the AWS infrastructure docs describe the VPC, compute, database and queues the platform provisions.

Run in your terminal to get started locally.
The per-environment variables from Railway become secrets set by environment type, and the code can guard against the classic staging mistake, a live key in a test environment or the reverse:
// billing/billing.ts
import { api, APIError } from "encore.dev/api";
import { appMeta } from "encore.dev";
import { secret } from "encore.dev/config";
// Was a Railway variable with a different value in each environment.
const stripeKey = secret("StripeSecretKey");
function keyForThisEnvironment(): string {
const key = stripeKey();
const isProduction = appMeta().environment.type === "production";
// Refuse to start work with the wrong kind of key for the environment.
if (isProduction && !key.startsWith("sk_live_")) {
throw APIError.failedPrecondition("production needs a live Stripe key");
}
if (!isProduction && key.startsWith("sk_live_")) {
throw APIError.failedPrecondition("non-production environments must use a test key");
}
return key;
}
export const environment = api(
{ expose: true, method: "GET", path: "/billing/environment" },
async (): Promise<{ name: string; type: string; cloud: string }> => {
keyForThisEnvironment();
const env = appMeta().environment;
return { name: env.name, type: env.type, cloud: env.cloud };
},
);
Set the values per type with encore secret set --type prod StripeSecretKey for production and encore secret set --type dev,preview,local StripeSecretKey for the rest, as described in the secrets docs. A single environment can override its type with --env, for example a second staging environment with its own key. The metadata fields used above are in the metadata docs.
Every app starts with a staging environment that deploys the main branch, and connecting your AWS account (see Connect your cloud account) lets you create production in it, deployed with git push encore or a branch trigger. With GitHub connected, each pull request also gets its own preview environment, hosted by Encore and separate from your connected AWS account, named after the pull request, which replaces Railway's PR environments and is removed when the pull request closes.
A coding agent that adds a service gets all three environments from the same change, and can run the service locally with test keys before anyone deploys anything.
Best fit: Projects moving from Railway to their own AWS account that want production in their own account and per-pull-request preview environments hosted by Encore, all created from one codebase, with secrets set per environment type.
Deploy the AWS staging environment, run the same smoke tests against it that you ran on Railway staging, and give the team a week on it before production moves. Production follows the same steps with a database migration and a DNS change, and Railway production stays running until the new environment has served real traffic for a full cycle.
A Railway environment is an isolated copy of every service in a project, with its own variables. On AWS the same isolation comes from a separate AWS account or a separate VPC and cluster per environment, each with its own databases, secrets and IAM roles.
Yes. Separate accounts give the strongest isolation, since an IAM mistake or a runaway cost in staging cannot reach production, and AWS Organizations makes them manageable. A single account with separate VPCs is cheaper to run but relies on careful IAM boundaries.
AWS has no built-in equivalent, so teams script one with CI that creates and destroys a service and database per pull request. A platform that creates a preview environment per pull request removes that script.
With Encore you declare each secret once in code and set a different value per environment type with encore secret set --type prod or --type dev,preview,local. A specific environment can also have its own value with --env, which takes precedence over the type.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.