liveBook · Manning

Declarative programming

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

A declarative approach specifies the desired state of a system without specifying the procedural actions or execution order needed to achieve it.

Declarative programming describes the desired state of infrastructure without listing the actions or execution order required to create it. Imperative code instead gives step-by-step instructions and manages dependencies explicitly. section 4.3.4 section 4.5

AWS CloudFormation expresses the desired infrastructure in a JSON or YAML template. CloudFormation interprets that description, handles dependencies, and determines how to reach the declared state. section 4.5

Declarative infrastructure supports several practical goals:

  • Consistency: teams use a common language instead of implementing infrastructure through unrelated scripts. section 4.5
  • Reproducibility: matching templates can create equivalent test and production environments. section 4.5
  • Customization and testing: parameters adapt templates, while temporary infrastructure can be created, tested, and removed. section 4.5
  • Updatability: changing the declared configuration lets CloudFormation identify and apply the required infrastructure changes. section 4.5 section 4.5.3

Changing a virtual machine

Rather than scripting each action needed to replace or reconfigure a virtual machine, change the relevant CloudFormation parameter or template value. CloudFormation determines what must change to reach the new result, then updates the stack. section 4.5.3

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Explains definition, imperative contrast, dependency handling, reproducibility, and updates without detailing CloudFormation’s internal reconciliation algorithm.
Examples
Uses virtual-machine creation, CloudFormation stack updates, parameter changes, and reproducible test and production environments.
What it assumes
Contrasts with imperative programming and assumes familiarity with infrastructure scripts or infrastructure-as-code blueprints.
What you can do after
Apply it via AWS CloudFormation by declaring infrastructure in JSON or YAML and updating the declaration when the desired state changes.
How it connects
Connects infrastructure as code with AWS CloudFormation, templates, dependencies, parameters, CDK, and Terraform.

Also explained in

Compare how 14 books explain declarative programming →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.