Cloud concept · Updated

Declarative Programming - Declarative programming describes the desired result or structure of a system while delegating the execution steps to a runtime, framework, or provisioning engine.

In short

Instead of prescribing each operation in order, engineers define resources, relationships, constraints, or interface states that a tool interprets. This approach supports repeatable infrastructure provisioning, reusable application components, API contracts, and visual AI workflows, but still requires testing, security controls, and lifecycle management.

Cloud Concepts Hub →

6 key aspects of Declarative Programming

Declarative programming combines outcome-focused definitions, reusable abstractions, and engine-managed execution while leaving engineers responsible for correctness, security, and lifecycle risks.

01
Outcome-focused definitions

Describe the required resources, interface state, contract, or workflow rather than every execution step. The interpreting engine supplies the operational procedure within the capabilities of its model.

02
Engine-managed dependencies

Resource references and workflow connections express relationships that an engine can use to order execution. Explicit dependencies are sometimes necessary when a relationship is not captured by the definition.

03
Reusable, versioned components

Modules, templates, and UI components package common patterns for reuse. Version and test these components so that a shared change does not unexpectedly alter every consuming environment.

04
State and lifecycle awareness

Infrastructure engines need information about managed resources to determine changes, but not every engine continuously reconciles drift. Understand state ownership, update behavior, deletion policies, and resource replacement before deployment.

05
Declarative contracts and composition

API specifications, UI descriptions, and workflow graphs declare structure and connections that tools interpret. They reduce procedural implementation work without eliminating backend logic, permissions, accessibility testing, or error handling.

06
Reviewable changes with operational limits

Plans, change sets, and version-control diffs help engineers inspect intended changes before execution. They do not guarantee successful deployment, reversible side effects, or preservation of application data.

Cloud services for Declarative Programming

CloudFormation can define the infrastructure supporting an application, while Amplify helps compose its frontend experience. API Gateway can expose a backend interface configured from a supported OpenAPI definition. Backend logic can invoke Amazon Bedrock Flows for AI processing or use Step Functions for broader application orchestration. Each service interprets a different kind of declaration: infrastructure resources, UI components, API contracts, or workflow structure. These definitions should be versioned and tested together, with explicit permissions and clear ownership boundaries. No individual declaration automatically ensures end-to-end accessibility, security, reliability, or consistent deployment across all layers.

AWS CloudFormationAWS CloudFormation

CloudFormation interprets declarative templates to provision and manage AWS resources as stacks. Parameters, nested stacks, change sets, and supported drift detection help engineers reuse definitions and manage infrastructure changes.

AWS AmplifyAWS Amplify

Amplify supports application development with UI components and libraries that can be composed into declarative frontend interfaces. Engineers must still implement and test accessible interaction, authentication flows, application state, and failure handling.

Amazon Bedrock

Amazon Bedrock Flows provides a visual builder for connecting supported AI workflow nodes and defining their data mappings. The service orchestrates the declared flow, while engineers configure permissions, validate inputs, and evaluate results.

Amazon API GatewayAmazon API Gateway

API Gateway supports importing OpenAPI definitions for supported API configurations, including AWS-specific extensions for integrations. The API contract describes the interface but does not replace backend implementation or guarantee enforcement of every OpenAPI constraint.

AWS Step FunctionsAWS Step Functions

Step Functions interprets state machines defined with Amazon States Language to orchestrate tasks, branches, retries, and error handling. Its visual workflow tools help engineers compose application processes without manually coding the orchestration loop.

Declarative Programming exam questions

Real practice exam questions on Declarative Programming, with the correct answer and its explanation. Answer them with every option in the exam simulator.

SAP-C03

A company uses one approved AWS CloudFormation template to deploy an Amazon RDS DB instance in each development and production environment. An EnvironmentType parameter accepts dev or prod. The DB instance must exist in both environments.

Production requires RDS Enhanced Monitoring with a 60-second collection interval and a dedicated IAM monitoring role created by the stack. Development must have Enhanced Monitoring disabled, must not create the monitoring role, and must omit the DB instance's MonitoringRoleArn property entirely. The same template must support both environments without preprocessing, custom resources, or post-deployment API calls.

Which template design meets these requirements?

Show answerCORRECT ANSWER

Define an IsProduction condition by comparing EnvironmentType with prod. Apply Condition: IsProduction to the monitoring role. Leave the DB instance unconditional. Set MonitoringInterval with Fn::If to 60 for production and 0 otherwise. Set MonitoringRoleArn with Fn::If to the role's ARN for production and Ref: AWS::NoValue otherwise.

A resource-level Condition prevents CloudFormation from creating the monitoring role in development. Property-level Fn::If expressions independently configure the DB instance. A false branch that returns AWS::NoValue removes MonitoringRoleArn rather than assigning an empty value. The conditional reference also avoids requiring an ARN from a role that does not exist in development.

AIP-C01

A retailer has an existing authenticated API that generates draft product descriptions. Three React applications hosted with AWS Amplify will let employees request a draft, review it, and approve it. The API and its authorization controls must remain unchanged.

The applications currently use separate event handlers to insert result elements, disable buttons, and display errors. After failed requests, some pages leave the approval button enabled or fail to announce the error to screen-reader users. The retailer wants a shared implementation in which reviewers can inspect the rendering rules for idle, generating, review-ready, and error states in one place. Each application must support keyboard operation and announce generation status without moving keyboard focus.

Which implementation best meets these requirements?

Show answerCORRECT ANSWER

Create a shared React component with Amplify UI primitives. Represent request status and the current draft in component state, derive button availability and displayed content from that state, and render a labeled status region with appropriate live announcements. Test state transitions, keyboard behavior, and screen-reader announcements.

This approach makes the interface a description of the current application state rather than a sequence of DOM mutations. A shared component centralizes rendering and interaction rules across applications. Explicit labels, live-region behavior, and accessibility testing address the accessibility requirements; using a UI library alone would not guarantee them.

DOP-C02

A platform team maintains a reusable logging component in an AWS CDK v2 TypeScript application. A release pipeline must synthesize the application once and promote the same generated CloudFormation template to development and production. Each deployment supplies an EnvironmentType parameter with an allowed value of development or production.

The component must retain logs for 7 days in development and 365 days in production. It must also create a CloudWatch alarm only in production; the alarm resource must not exist in development. The deployment jobs cannot rerun the CDK application or modify the synthesized template.

Which implementation meets these requirements?

Show answerCORRECT ANSWER

Define EnvironmentType as a CfnParameter and create a CfnCondition that compares it with production. Use Fn.conditionIf for the log group's RetentionInDays property, and assign the condition to the alarm's underlying CfnAlarm resource through cfnOptions.condition.

This preserves the environment-dependent decisions in the synthesized template. CloudFormation evaluates the parameter and condition during each deployment. Fn.conditionIf selects the appropriate retention period, and the resource condition ensures that the alarm is created only in production. Both environments can therefore use the same synthesized artifact.

Practice Declarative Programming in a full exam

Questions on Declarative Programming in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

What is Declarative Programming

3 min read

Declarative programming separates the description of an intended outcome from the mechanics used to achieve it. An imperative script might issue commands to create a network, create a subnet, and then launch a server. A declarative definition describes the network, subnet, server, and their relationships; an execution engine determines the necessary operations. The distinction concerns who specifies the execution procedure, not whether the definition uses JSON, YAML, or a general-purpose programming language.

Infrastructure as code is a common cloud application of this approach. An AWS CloudFormation template or Terraform configuration can declare a private database, its subnet placement, and its security rules. References between resources establish dependencies, allowing the provisioning engine to order operations. Parameters, modules, and nested stacks support reusable components across development, staging, and production. Version-controlled definitions make changes reviewable and provide a record of intended configuration throughout a system's lifecycle.

Different tools implement this model differently. CloudFormation manages resources through stacks and supports change sets for reviewing proposed updates. Terraform uses configuration, provider behavior, state, and refreshed resource information to construct an execution plan. AWS CDK lets engineers use general-purpose languages to generate CloudFormation templates: the authoring code can contain imperative constructs even though the resulting infrastructure model is declarative. Tool selection should consider resource coverage, team skills, state management, deployment boundaries, and recovery procedures rather than syntax alone.

Declarative infrastructure does not necessarily imply continuous reconciliation. Kubernetes controllers repeatedly compare desired and observed state, whereas a stack-based deployment tool generally acts when a deployment operation is requested. Out-of-band changes can therefore persist until detected and addressed. Drift detection also has coverage limits. Reapplying an unchanged definition is generally intended to avoid unnecessary changes, but custom resources, external dependencies, and provider behavior can introduce side effects.

The same idea applies to application interfaces. Declarative UI components describe what should appear for a given application state, while a UI framework handles rendering updates. AWS Amplify can support frontend development with reusable UI components and integration libraries. For an AI chat interface, engineers might compose an authenticated conversation view with loading, error, and response states. Declarative components do not automatically make that interface accessible: keyboard navigation, focus management, labels, screen-reader announcements, and streamed-response behavior still require design and testing.

API-first development uses specifications such as OpenAPI to declare paths, request schemas, responses, and security requirements. Tooling can use that contract for documentation, client generation, validation, or supported API configuration imports. However, the specification does not implement business logic or automatically enforce every declared constraint. An AI inference endpoint still needs authentication, authorization, backend integration, input handling, and operational safeguards.

Visual AI workflow builders provide another application. Amazon Bedrock Flows, also described as prompt flows, lets engineers connect nodes for prompts, model calls, data processing, and other supported operations. The graph declares connections and data movement while the service orchestrates execution. No-code composition does not eliminate engineering responsibility: input mappings, execution permissions, model access, failure behavior, and output quality must be validated.

The main trade-off is exchanging explicit procedural control for abstraction. Definitions can be easier to review and reuse, but failures may require understanding the engine's dependency graph and lifecycle rules. A small property change can replace a stateful resource, and rollback cannot always recover deleted data or reverse external side effects. Review change sets or plans, protect state and secrets, test reusable components, and apply backup and retention policies before production changes. For exam scenarios, favor declarative approaches when the requirement emphasizes desired state, repeatability, reusable definitions, API contracts, or visual composition—not merely because a file is labeled configuration.

Learn Declarative Programming in lessons

5 short lessons on Declarative Programming in 3 certification courses.

Open the lessons