TwiceToldby Develoker
ConceptsSystem designLabsCheat sheetsAbout

Develoker makes free tools for learning to build software. TwiceTold explains each idea twice, as an everyday analogy and the real thing; CloudArch lets you design cloud systems and put load on them.

About ยท Labs ยท Cheat sheets ยท Learning paths

โ† Back to AWS CloudFormation and CDK

๐Ÿ“ AWS CloudFormation and CDK: cheat sheet

๐ŸŽจ The analogyBuilding a house from a written plan, with a foreman who lists every change before laying a brick.
๐ŸŽ“ The regular explanationInfrastructure as code on AWS. A CloudFormation template declares resources, parameters and outputs; CloudFormation creates them as one stack in dependency order, previews updates as change sets, rolls back on failure and detects drift. The CDK generates those templates from TypeScript, Java, Python and other languages.
From template to stackStep 4 of 4
๐Ÿ  Practice houseCREATE_COMPLETE๐Ÿก Real houseCREATE_COMPLETE๐Ÿ—„๏ธ Plan drawerv1 reviewed๐Ÿง‘Youendpoint, ARN๐Ÿ‘ทForeman๐Ÿ›–Shed๐Ÿ”Strongroom๐Ÿ›–Shed๐Ÿ”Strongroom
  1. You draw one plan of the whole house and put it in the drawer. A friend checks it first, and every old version stays in the drawer too.
  2. The plan goes to the foreman with one blank filled in, practice. The foreman builds every part on it and treats them all as one house.
  3. When the house is done, the foreman hands back the facts you need, like the address and where the key is.
  4. Want the real house? Hand over the same plan with the blank filled in differently. You get the same house again, part for part.
Ordering by dependenciesStep 5 of 5
RefRefvia subnet groupRefGetAtt๐Ÿ‘ทForeman๐ŸŒฑPlotโœ“๐ŸงฑFoundationโœ“๐Ÿ”‘Door lockโœ“๐Ÿ”Strongroomโœ“๐Ÿ”จWorkshopโœ“
  1. The foreman reads the plan and notes what needs what. The foundation and the door lock need the plot. The strongroom needs both, and the workshop needs the strongroom.
  2. Nothing can start before the plot, so the plot comes first.
  3. The foundation and the door lock don't need each other, so two builders do them at the same time.
  4. With the foundation and the door lock both done, the strongroom can go up.
  5. Last comes the workshop, which needs to know where the strongroom is. Taking it all apart later goes in the reverse order.
Previewing an updateStep 6 of 6
๐Ÿก The house๐Ÿง‘You๐Ÿ‘ทForeman๐Ÿ“‹ Change list๐Ÿ›–Shedsame ID๐Ÿ”New strongroomempty
  1. You want the shed painted green and the strongroom moved. Before any work, you ask the foreman for a list of exactly what they would do.
  2. The list says the shed just gets painted, but the strongroom would be knocked down and rebuilt, and whatever is inside would go with it.
  3. You say go ahead. The shed gets its coat of paint where it stands.
  4. For the strongroom, the foreman builds a new one first and moves everything that pointed at the old one over to it.
  5. Then the old strongroom is knocked down, along with whatever was still inside it. The new one starts empty.
  6. Only the new, empty strongroom is left standing.
Rolling back a failed updateStep 4 of 4
๐Ÿก The houseUPDATE_ROLLBACK_COMPLETE๐Ÿง‘You๐Ÿ‘ทForeman๐Ÿ›–Shedv1
  1. A new job starts. The foreman paints the shed and starts putting up a new workshop.
  2. The workshop's walls won't go up. That part of the job has failed.
  3. The foreman undoes the whole job. The shed goes back to its old colour and the half-built workshop is cleared away.
  4. The house is exactly as it was before, and you get a note saying what went wrong so you can fix the plan.
Detecting driftStep 4 of 4
๐Ÿก The houseIN_SYNC๐Ÿง‘You๐Ÿง‘โ€๐Ÿ”งHelper๐Ÿ‘ทForeman๐Ÿ›–ShedIN_SYNC๐Ÿ”StrongroomIN_SYNC
  1. A helper takes out the strongroom's alarm by hand, without touching the plan. Now the house and the plan disagree.
  2. You ask the foreman to check. They walk round the house with the plan and look at every part.
  3. The shed matches the plan; the strongroom doesn't. The foreman marks it, but doesn't change anything.
  4. You put the alarm back, and the next check finds the house and the plan agree again.
From CDK code to a stackStep 3 of 3
๐Ÿก The houseCREATE_COMPLETEโœ๏ธ Your description๐Ÿง‘โ€๐ŸŽจDraughtsman+ 1 bucket๐Ÿ“ Full plan๐Ÿ‘ทForeman๐Ÿ›–Safe shed
  1. You describe what you want in your own words, using a ready-made design, a safe shed with a lock. The draughtsman turns it into the full, detailed plan.
  2. Before any building, the draughtsman compares the new plan with the last plan the foreman built from, and tells you what would change.
  3. Then the plan goes to the same foreman as always, who builds it exactly as before.

๐Ÿงฉ Key questions

The plan says the workshop needs to know where the strongroom is. What does the foreman do?
Builds the strongroom first, then the workshop. The foreman works out the order from what needs what. Parts that don't need each other are built at the same time.
The change list says the strongroom would be knocked down and rebuilt. Why does that matter?
Whatever is inside the old strongroom goes with it. That's why you ask for the list first: you see it on paper before anyone picks up a hammer.
Halfway through a job, the new workshop's walls won't go up. What do you end up with?
The house exactly as it was before the job, plus a note saying what went wrong. The foreman undoes the whole job, so you never live in half a house.
A helper takes out the strongroom's alarm by hand. What does the foreman's check do about it?
Marks the strongroom as not matching the plan, and leaves fixing it to you. The check only reports. You either put the change back or write it into the plan.
You describe a safe shed in your own words with the kit. Who actually builds it?
The same foreman, from the full plan the draughtsman drew. The kit only writes the plan. The foreman builds, lists changes and undoes failed jobs, just as before.