Updated Nov 23, 20266 min read

How to Move Heroku Config Vars to AWS Secrets

A step-by-step guide to moving Heroku config vars to AWS: which ones are secrets, how ECS injects Secrets Manager values, what changes when a value rotates, and a TypeScript version where each secret is declared in code.

Illustration for How to Move Heroku Config Vars to AWS Secrets

Heroku config vars are one flat list of key-value pairs, and an app reads DATABASE_URL, STRIPE_SECRET_KEY and LOG_LEVEL the same way. Whenever one of them is set or removed, Heroku restarts the app and creates a new release.

On AWS that single list splits into environment variables for settings and Secrets Manager values for secrets, with an IAM permission for each secret. This guide sorts the list, shows how ECS injects the values, and then declares the same secrets in code.

How do Heroku config vars map to AWS?

Heroku config varsAWS
Plain settingsConfig varsEnvironment variables in the ECS task definition
SecretsConfig vars, same listSecrets Manager or Parameter Store, referenced from the task definition
Add-on valuesDATABASE_URL, REDIS_URL set by add-onsCreated with the RDS or ElastiCache resource
Change takes effectApp restarts and a release is createdNew task deployment, forced by you for secrets
Who can read themAnyone with app access, via heroku configIAM permission on the secret and the task execution role
Per-environment valuesSeparate app or pipeline stage per environmentSeparate secret per environment

The Heroku behavior is from the config vars article, and the ECS side from the Secrets Manager injection docs, both checked on November 23, 2026.

Step 1: Export the list and sort it

Run heroku config --shell -a my-app > config.txt and go through it line by line. Anything set by an add-on, such as DATABASE_URL, REDIS_URL or PAPERTRAIL_API_TOKEN, belongs to a resource you are about to replace and should not be copied at all. Values that are safe in a log, like LOG_LEVEL or FEATURE_NEW_CHECKOUT, go into the task definition as plain environment variables, and everything else is a secret: API keys, signing keys, OAuth client secrets and webhook secrets. The file holds every secret in plain text, so create it with umask 077 on an encrypted disk, keep it out of synced folders, and delete it as soon as the values are stored. Rotate any value that may have leaked along the way.

Check the code for names the list does not show, because some apps read a variable that only exists on the review apps or the staging app, and the production list will be missing it.

Step 2: Store the secrets and wire them to ECS

Create one Secrets Manager secret per value (or one JSON secret per service and reference its keys), and add a secrets block to the container definition that points each environment variable name at the secret's ARN. The task execution role needs secretsmanager:GetSecretValue on exactly those ARNs, which is the detail that most often turns into a task that stops with ResourceInitializationError on its first start. The ECS documentation is clear that a task reads the value once at launch, so changing a secret later does nothing until you use Force new deployment on the service.

Plan one secret per environment from the start, for example prod/stripe-key and staging/stripe-key, since Heroku apps and pipeline stages each had their own list and AWS will not separate them unless the names do.

Step 3: Declare the secrets in code

Encore brings infrastructure from code, and a secret becomes a secret() call in the service that uses it, so the list of what the app needs is in the repo while the values are not. Per the secrets docs, Encore stores values encrypted and, when you deploy to your own AWS account, provisions AWS Secrets Manager and injects the values into the container as secret environment variables.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.
Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

A payments service that read two Heroku config vars, with the secret declared and the plain setting chosen by environment type:

// payments/payments.ts import { api, APIError } from "encore.dev/api"; import { appMeta } from "encore.dev"; import { secret } from "encore.dev/config"; // Was STRIPE_SECRET_KEY in the Heroku config; STRIPE_WEBHOOK_SECRET is declared the same way. const stripeKey = secret("StripeSecretKey"); // Was LOG_LEVEL, a plain setting that does not need to be secret. const verbose = appMeta().environment.type !== "production"; interface ChargeRequest { customerId: string; amountCents: number; } export const charge = api( { expose: true, method: "POST", path: "/charges" }, async (req: ChargeRequest): Promise<{ id: string }> => { if (req.amountCents <= 0) throw APIError.invalidArgument("amount must be positive"); const resp = await fetch("https://api.stripe.com/v1/payment_intents", { method: "POST", headers: { Authorization: `Bearer ${stripeKey()}`, "Content-Type": "application/x-www-form-urlencoded", // Safe to retry: the same customer and amount in the same minute is one charge. "Idempotency-Key": `${req.customerId}-${req.amountCents}-${Math.floor(Date.now() / 60000)}`, }, body: new URLSearchParams({ amount: String(req.amountCents), currency: "usd", customer: req.customerId, }), }); if (!resp.ok) { if (verbose) console.error("stripe error", resp.status, await resp.text()); throw APIError.unavailable("payment provider error"); } const body = (await resp.json()) as { id: string }; return { id: body.id }; }, );

Set the values once per environment type with encore secret set --type prod StripeSecretKey, and use --type dev,preview,local for test keys. The deploy fails when a declared secret has no value, which catches the missing production-only variable from step 1 before the app starts. Encore secret values are not stored in the repo, so an AI coding agent working in it can read the secret names but not the values. Locally, a missing secret shows a warning, and a .secrets.local.cue file overrides values for one machine.

To deploy, connect your AWS account as described in Connect your cloud account and push with git push encore. Rotating a value is encore secret set followed by a new deploy, in place of editing Secrets Manager and forcing an ECS deployment by hand.

A coding agent that adds a new provider integration declares the secret next to the code that calls it and runs the service locally with a test key, and the secret arrives in AWS with the next deploy.

Best fit: Apps leaving Heroku for their own AWS account that want each secret listed in the code that uses it, with values kept out of the repo.

Step 4: Cut over and rotate

Deploy the AWS version with the same provider keys first, confirm it works against the live services in a staging environment, and only then change DNS. After the switch, rotate every secret that was in the Heroku list, since each one has been visible to everyone with app access and to the exported file.

Frequently asked questions

What is the AWS equivalent of Heroku config vars?

Plain settings map to environment variables on the ECS task definition, and secrets map to AWS Secrets Manager or Systems Manager Parameter Store values injected into the container as environment variables. Heroku treats both the same way, so the first step is to sort your config vars into those two groups.

Do I need to restart ECS tasks after changing a secret?

Yes. ECS reads the secret when the task starts, so a task keeps the old value after the secret changes until you force a new deployment. Heroku also restarts the app whenever a config var changes, so the behavior is similar, but on ECS the restart is a step you trigger yourself.

What happens to DATABASE_URL when I leave Heroku?

DATABASE_URL is set by the Heroku Postgres add-on and disappears with it. On AWS the connection string comes from the new RDS instance, so it is created and injected as part of the database setup instead of being copied from the old app.

How do I keep secrets out of my repository on AWS?

With Encore you declare each secret in code with secret() and store its value with encore secret set, so the value never lands in the repo. On deploy, Encore stores the secret in AWS Secrets Manager in your account and injects it into the service as a secret environment variable.

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.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders