Skip to content
cdkd

cdkd rollback: limitations

A rollback puts resources back, but some changes cannot be undone completely. This page covers the cases that need explaining. The short list of every limitation is on cdkd rollback, and the plan that cdkd rollback prints shows which ones apply before you confirm.

Reversing a replacement

When the failed deploy replaced a resource, the rollback takes the old resource back and deletes the new one. A create-first replacement deletes the old resource only after the rest of the deploy succeeds, so after a failed deploy it is still in AWS: the rollback adopts it again, and its data is kept. In a nested stack the delete waits for the whole stack tree's deploy, so a top-level deploy that fails after a child finished still finds the child's old resource, and its revert of the child adopts it again. The plan labels such an operation reverse-replace.

Resources removed from the template wait the same way: the deploy deletes them only after it succeeded, in the same cleanup phase as the old resources of its replacements, ordered by what each one uses (an old Lambda alias goes before the removed version it points at). After a failed or interrupted deploy every removed resource is still in AWS and in state, and the rollback leaves it alone: it neither creates it again nor deletes it, and the next deploy deletes it. An interrupt or a failed delete during that cleanup phase rolls nothing back, as CloudFormation never rolls a cleanup back: what it has not deleted stays in state, the deploy exits 2, and the next deploy deletes it. When a stack of the same cdkd deploy run imports this stack's outputs, the whole cleanup phase, removed resources included, waits until that stack deployed. A removed resource that an old resource kept for a consumer still uses (an alias still pointing at a removed version) is kept with it: cdkd sends no delete for it, the deploy exits 2, and the next deploy deletes it.

The same wait applies to a record holding a NoEcho value and to a resource under UpdateReplacePolicy: Snapshot, whose final snapshot is taken when the old resource is deleted, after the rest of the deploy succeeds:

Type Old copy's snapshot New copy's delete by a rollback
RDS instance or cluster, Neptune or DocumentDB cluster, ElastiCache cache cluster Taken by the delete call Takes a final snapshot first: the new copy may already hold writes
EBS volume, Redshift cluster, ElastiCache replication group Taken and waited for right before the delete, never before the create Takes none

A failed deploy takes no snapshot of the old resource. Both copies stay in AWS, and are billed, until the deploy ends, and writes that reach the old copy meanwhile are in its snapshot.

A few cases delete the old copy before the deploy succeeds:

Case When the old copy is deleted Why
An IAM inline policy Right after the new one is created Both policies attached until the deploy ends would grant the union of their permissions.
A new resource with the old one's physical id and type, such as a Glue table moved to another database or a security group ingress rule moved to another source Right after the new one is created The id now names the new resource, so a later delete could not address the old one.
An SNS subscription whose change cannot be applied in place Before the new one is created SNS returns the existing subscription for the same topic, protocol and endpoint.
A Route 53 record set whose name, type or set identifier changes In the same change batch that creates the new one Route 53 keys a record on them; one batch swaps the two at once, so the name never stops resolving.
A security group ingress rule whose description changes while its recorded description is redacted Before the new one is authorized EC2 keys a rule on its protocol, ports and source, so the same rule cannot be added while the old one is there.
A VPC gateway attachment or a subnet route table association, unless UpdateReplacePolicy: Retain keeps it Before the new one is created AWS allows one gateway per VPC and one route table per subnet, so it refuses the new one while the old exists. CloudFormation deletes it first too.
An update AWS rejects as unsupported, on a resource whose name cannot change Before the new one is created Only one copy can hold the name. A stateful type also needs --force-stateful-recreation.
--replace, --recreate-via-cc-api or --recreate-via-sdk-provider Before the new one is created You asked for delete-first. A resource stored inside the re-created one goes with it.

The rollback re-creates such an old resource from the properties the journal saved. Nothing is lost for an inline policy. A security group ingress rule, and a Route 53 record set whose set identifier alone changed, keep their ID, so the rollback puts them back in place with their recorded properties. For any other type, the rollback output and the cdkd rollback plan say that what AWS held for the old resource beyond its recorded properties, such as queued messages or subscriptions made outside the stack, does not come back.

The deploy's plan names the cases it can predict before anything runs: cdkd diff and the cdkd deploy --require-approval listing end the replacement's line with when the old resource is deleted and that a failed deploy's rollback does not restore what AWS held for it beyond its recorded properties. That covers the SNS subscription, the Route 53 record set whose name changes, and the --recreate-via-* flags (in the approval prompt; a target whose replacement takes another name is created first, so its note says "unless"). The others are decided during the deploy, so the plan cannot name them: an update AWS rejects, a new resource that turns out to hold the old one's physical ID and type, and --replace after a name collision. A Route 53 record set whose type changes is shown as an update, as CloudFormation shows it, so it gets no note, although the record gets a new ID and the rollback output says it is re-created. A set identifier change and a security group ingress rule keep their ID and are reverted in place. An inline policy loses nothing, so it gets no note.

Warning

For a type that holds data (DynamoDB, RDS, S3 and so on), an old resource that was deleted right away, or first, lost its data. The rollback does not recover it: the re-created resource starts empty. This does not apply under UpdateReplacePolicy: Retain, where the old resource was kept.

A waiting delete is kept in state, so a deploy that stops before its end leaves the old resource for the next cdkd deploy or cdkd destroy to delete. Two cases wait in memory only, and are never written to state:

Case Why it is not written to state
A custom resource or nested stack whose delete needs a NoEcho value cdkd never writes that value to state.
An old physical id another resource of the stack also records, such as a queue whose queue policy is recorded under the queue URL A later run would delete the other record's resource.

A deploy killed before its end (SIGKILL, a power loss) leaves such an old resource in AWS, untracked; a deploy that fails or is stopped with Ctrl-C says so in its output. After a failed deploy run with --no-rollback, cdkd rollback adopts the old resource again; a later cdkd deploy does not track it, so delete it by hand if you deploy forward instead.

Under UpdateReplacePolicy: Snapshot, that later delete takes the promised snapshot first:

  • --skip-final-snapshot on the later run does not skip it: only the deploy that replaced the resource could.
  • A copy AWS cannot snapshot yet (a paused Redshift cluster, a modifying replication group) is not deleted, and the next run tries again.
  • Once the snapshot is taken, a delete that then fails is retried without another one.
  • A Ctrl-C while the snapshot is being taken stops before the delete. The next run reuses that snapshot for an EBS volume, or while a Redshift or replication group snapshot is still being taken, and takes a new one otherwise. Only a snapshot started since the replacement is reused.
  • A deploy killed outright during the delete still lists the copy as owing its snapshot. The next run reuses an EBS volume's snapshot, takes one more of a Redshift cluster or replication group, or, for one already being deleted, warns that it cannot until the copy is gone.

The rollback works in the same order the deploy did:

The deploy The rollback
Created the new resource first, with the old one's delete still waiting Adopts the old one again, then deletes the new one
Created the new resource, then deleted the old one right away Re-creates the old one, then deletes the new one
Deleted the old one first Deletes the new one, then re-creates the old one
Kept the old one (UpdateReplacePolicy: Retain) Adopts the old one again; re-creates nothing
Created the new resource first, then could not delete the old one right away Checks AWS for the old one first: re-creates it if gone, adopts it again if AWS had refused its delete or it was never sent, and otherwise changes nothing and keeps the journal (details)

A deploy deletes the old resource first under --recreate-via-*, on the delete-first path of --replace, and when it falls back to a replacement after AWS rejected an update. On a stack with a stackInstanceId, the first and last of those create first for a resource your template does not name, because the new resource gets the next generated name.

When the old name is still taken

If the deploy created the new resource first and deleted the old one right away, the old resource's name may still be held by the new one when the rollback tries to re-create the old one.

cdkd deletes the new resource first in that case, but only when it can show that the new resource is what holds the name. If something else holds the name, or cdkd cannot tell, the operation fails. Nothing is deleted, the message gives the name, and the journal is kept. Then do one of these:

  • Remove or rename whatever holds the name, and run cdkd rollback again.
  • If the new resource itself holds the name, delete it by hand and run cdkd rollback again.
  • Pass --orphan <logicalId> to leave that resource alone.

UpdateReplacePolicy: Retain also protects the new resource

If the resource the replacement created declares UpdateReplacePolicy: Retain, the rollback does not delete that new copy. The copy keeps running and is removed from the state record. The rollback warns and exits 2, and cdkd events records the copy's physical ID.

CloudFormation does the same and reports DELETE_SKIPPED for the new copy. Only UpdateReplacePolicy has this effect; DeletionPolicy does not.

So when the deploy kept the old resource, both copies survive the rollback, and the state record names the old one.

A copy that keeps a fixed name still holds it after the rollback, so the next deploy that asks for that name is refused. The refusal says that this stack's event history records the kept copy under that name. If the holder is that copy and you no longer need it, delete it; otherwise choose another name.

One combination fails: the old resource has to be re-created, and its name is held by a new resource that is retained. The operation fails and the journal is kept. Delete the new resource yourself, or remove UpdateReplacePolicy: Retain, then run the rollback again.

Edge cases

  • A failed delete on the delete-first order. The state record keeps naming the new resource, and the journal is kept.
  • A failed re-create on the delete-first order. The resource is then absent, and the message says so. Run cdkd deploy to fix it forward.
  • A deploy whose new copy failed to create after the old one was deleted first. The automatic rollback and cdkd rollback (with or without --revert-failed) re-create the old one from its recorded properties, under the same name, whichever order or flag deleted it (--replace for a custom name, --recreate-via-cc-api, --recreate-via-sdk-provider, or the fallback for an update the type cannot apply), for any type. Its data does not come back; a final snapshot taken at the delete stays where it was, for you to restore. While the new copy it left is still there, the rollback does not re-create the old one: a copy whose delete failed is retried with it on the next run, and a retained copy leaves a warning instead.
  • A resource re-created under its own name that holds other resources. When the deploy deleted and re-created a resource under the same name, and the stack records a resource AWS stores inside it (a function's permission, a topic's subscription, a role's inline policy), the rollback refuses that resource: deleting it again would take the other one too. Nothing is deleted. Deploy the previous template with cdkd deploy --replace, or orphan the resource.
  • A resource re-created under its own name whose only change was a secret. When every property the deploy changed is redacted the same way in state before and after, state cannot tell whether an earlier rollback already reversed it, so the rollback refuses that resource before deleting anything. Deploy the previous template with cdkd deploy --replace, or orphan the resource.
  • A re-create that fails after it made the resource. The rollback deletes what the re-create made, unless the old resource's DeletionPolicy is Retain or Snapshot. A resource it keeps or cannot delete is named in a warning.
  • A replacement that changed the resource's Type. The rollback reverses it through both types, and the plan shows the pair as from NEW to OLD. If the journal cannot name the old type, the plan shows the operation as (REFUSED), and it fails during the rollback with the journal kept. See Type changes on an existing logical id.

The rules for what counts as a replacement, when the order changes, and how cdkd decides who holds a name are in cdkd rollback internals.

NoEcho values are not reverted

A property that takes its value from a NoEcho parameter is left as AWS holds it. If the failed deploy changed that value, it stays changed after the rollback. Run cdkd deploy with the old value to restore it.

The reason is that cdkd never stores a NoEcho value. The state record holds only the mask *** for it, so the rollback has no old value to send. When it reverts the resource, it reads that property back from AWS and leaves it as AWS holds it. The same applies to a NoEcho attribute read through Fn::GetAtt.

The value never appears in the state record, the events or the log in the clear, and cdkd never sends *** to AWS. There are two exceptions: a name or other identifier is stored as resolved, and a value shorter than 4 characters can appear inside a longer log line. See State Store.

Edge cases

  • The value cannot be read back. This happens for a write-only property, a type that offers no read, or a read that failed. The operation fails with ROLLBACK_REDACTED_BASELINE, sends nothing, and the journal is kept. Restore the property with cdkd deploy.
  • Reversing a replacement fails the same way, because there is no live resource to read the value from.
  • A nested stack that receives the value as a Parameters entry reverts as usual.

Nested stacks

A nested stack has its own rollback journal. To revert a nested stack, the parent's rollback replays the nested stack's journal for the same deploy run, and the plan lists that replay under the parent's entry.

Run the rollback on the top-level stack:

cdkd rollback MyStack

If the nested stack's own deploy failed in that run, a plain rollback of the parent refuses. Pass --revert-failed, which replays the nested stack's completed operations. The resource that failed inside the nested stack then needs its own rollback:

cdkd rollback MyStack --revert-failed
cdkd rollback 'MyStack~MyNestedStack' --revert-failed

A plain cdkd rollback 'MyStack~MyNestedStack' is enough for the second command when that resource is a failed CREATE that made its resource.

Edge cases

  • The nested stack has no journal for the run. An older cdkd wrote it, or the journal was removed. The parent's entry fails and the journal is kept.
  • The nested stack's replay skipped an operation. The parent's entry is reported as partial, and the rollback exits 2.
  • You roll back the nested stack directly while the parent's journal still holds the run. The command is refused, and the message names the top-level stack to roll back. It is also refused while the parent's journal cannot be read, or while a running deploy holds the top-level stack's lock.
  • A nested stack's journal for a run the parent no longer holds. The plan lists it, and cdkd discards it after you confirm.
  • cdkd rollback without a stack name does not offer a nested stack's journal separately when its parent has one.
  • A secret reference that names no region. A reference written as a name carries no region; an ARN does. A record a deploy wrote since state schema v12 also says which region resolved it, and the rollback resolves it there. Without that, such a reference is refused when a stack above the nested stack reads a value from another region, and always in a direct rollback of the nested stack. The operation fails and the journal is kept. Set the property yourself, or write the reference as a full ARN.

A deploy that was killed

A deploy records its rollback journal when it stops. A deploy you interrupt with Ctrlc finishes the operations in progress and then records it. A second Ctrlc (or the SIGTERM a CI runner sends after its SIGINT when a job is cancelled) and a closed terminal (SIGHUP) exit at once, but record it first: the operations already completed, and those still in progress as failed operations, because their outcome is unknown. Pass --revert-failed to revert those too. A force-quit prints the cdkd rollback command to run and exits 130; a closed terminal exits 129. Release the stack lock either one leaves with cdkd force-unlock first.

The journal write is bounded by the same five seconds the force-quit allows for aborting asset uploads. When it does not finish in time, the deploy says so, and cdkd rollback may find nothing to revert. A cancelled GitHub Actions job allows less: it sends SIGKILL about 2.5 seconds after the SIGTERM that force-quits the deploy, and a journal write still in progress then is lost with the process.

A deploy that is killed outright runs none of this: kill -9, an out-of-memory kill, a CI runner's final SIGKILL, or a power loss leave the resources already changed in AWS and in the state record, with no journal entry for that deploy. cdkd rollback does not revert them: it replays only an older failed deploy's journal, when one is still there, and reports nothing to roll back otherwise. Deploy the previous version of the app to put the stack back. When it was the stack's first deploy, deploy again to finish it, or run cdkd destroy to delete what it created.

A successful deploy deletes the journal its earlier failed deploys left. When it is killed after it saved its state, or the delete fails, the journal stays behind, but the deploy's state record names what it superseded: cdkd rollback replays none of it, so it does not delete a resource the successful deploy kept or reset its updates. It still deletes a resource the failed deploy created that no state record holds. The next successful deploy removes the journal.

A nested stack whose deploy was in progress is recorded like one whose own deploy failed: see Nested stacks.

Names of re-created resources

A resource the rollback re-creates gets the physical name the failed deploy would have given it. You do not pass --prefix-user-supplied-names again: the journal records whether the deploy ran with that flag, and the rollback uses the same setting.

On a stack with a stackInstanceId, a replaced resource your template does not name is re-created under the generated name it had before the deploy, not the next one the replacement used. The state record also remembers the replacement's name, so the next replacement picks a name neither copy held.

Edge cases

  • A journal written by an older cdkd does not record the setting. The rollback then takes it from CDKD_PREFIX_USER_SUPPLIED_NAMES, then from the cdk.json in the current directory, then uses the default (no prefix). It prints a warning that says which one it chose. If the failed deploy ran with the prefix, run:

    CDKD_PREFIX_USER_SUPPLIED_NAMES=true cdkd rollback MyStack
    
  • A resource an earlier deploy created under the other setting keeps its name. This concerns the types whose names the setting rewrites: IAM roles, users, groups, instance profiles and managed policies, and ELBv2 load balancers and target groups. For those the rollback goes by the resource's physical ID. It prints a line when that differs from the failed deploy's setting, and a warning when neither setting produces the name.

Interaction with cdkd import

If you ran cdkd import on a stack after its failed deploy, the rollback leaves the imported resources alone.

This protects a resource you re-created by hand. Suppose a resource has an explicit name, so its physical ID is that name. The deploy created it and failed. You then deleted it, created it again by hand under the same name, and imported it. The journal still says "this deploy created that name". Without protection, the rollback would delete your resource.

So cdkd import marks each resource it adopts in the journal, before it writes state. The rollback then runs none of the journaled operations for that logical ID. What you see depends on what the journal recorded:

  • The same resource the import adopted (same physical ID and type; for a delete, the entry the import removed). The rollback leaves it alone. Plan line: adopted by cdkd import after this deploy, left as it is.
  • A different resource under the same logical ID (another physical ID or type). The rollback leaves it alone, warns, and exits 2. Plan line: recorded <its physical id>, which cdkd import has since replaced under this id; not reverted, check that resource by hand.
  • A replacement whose new resource the import adopted, while the old one was kept or may have been kept. The rollback leaves it alone, warns, and exits 2. The plan line starts with replaced <old physical id> but kept it or and may have kept it, and ends with not reverted, check that resource by hand.

"May have been kept" applies when the journal recorded no verdict, as on a failed operation. A replacement here includes a Type change that kept the resource's name.

Edge cases

  • A replacement. Only its new resource counts as what the operation recorded. If the import put the old resource back, the replacement is left running and reported as in the third case.
  • Failed operations follow the same rules, with or without --revert-failed.
  • Events. An operation that is passed over records a ROLLBACK_RESOURCE_SKIPPED event. Once its segment is removed from the journal, the plan line, which names the physical ID, is the record to act on.
  • --orphan. Completed operations of an ID you pass to --orphan are not covered by the mark. The flag is honoured.
  • Later deploys. Segments that later deploys add carry no mark and are replayed as usual.
  • The import cannot read or write the journal. It refuses and writes no state.
  • An import by an older cdkd wrote no mark. A failed create whose physical ID such an import replaced is still left alone with a warning (exit 2), but the plan line cannot say that an import caused it.

Interaction with cdkd export

cdkd export hands a stack over to CloudFormation. While a rollback journal exists for the stack, it refuses to do so unless you confirm. Roll back or re-deploy first.

Last updated: