Courseiva
SDLC AutomationeasyMultiple ChoiceObjective-mapped

DOP-C02 SDLC Automation Practice Question

A company uses AWS CloudFormation to deploy infrastructure. They have a template that creates an Amazon EC2 instance and an Elastic IP address. The template uses the AWS::EC2::EIP resource. The team notices that when they delete the stack, the Elastic IP address is not released, leading to charges. They want to ensure that the Elastic IP is automatically released when the stack is deleted. What should they do?

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Set the DeletionPolicy attribute to 'Delete' on the EIP resource

The default DeletionPolicy for AWS::EC2::EIP is 'Retain', meaning the Elastic IP address is preserved after stack deletion, leading to charges. To ensure it is automatically released, you must explicitly set the DeletionPolicy attribute to 'Delete' on the EIP resource. This overrides the default and causes the Elastic IP to be deleted upon stack deletion. Option A (Retain) would keep the EIP, which is the default and would still incur charges. Option B (custom resource) is unnecessary. Option D (DependsOn) does not control deletion behavior. Therefore, Option C is the correct solution.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Set the DeletionPolicy attribute to 'Retain' to keep the EIP

    Why it's wrong here

    Setting DeletionPolicy to 'Retain' explicitly tells CloudFormation to preserve the EIP resource when the stack is deleted. Since AWS bills for EIPs even when they are not associated with a running instance, this would leave an orphaned Elastic IP that incurs recurring charges indefinitely. This directly contradicts the goal of avoiding ongoing costs, making it the wrong choice for managing EIP cleanup.

  • Create a custom resource to release the EIP before stack deletion

    Why it's wrong here

    Creating a custom resource to release the EIP before stack deletion is an unnecessary workaround because CloudFormation already handles the release natively when the EIP resource has the default DeletionPolicy of Delete. Adding a custom resource introduces extra Lambda logic and potential failure points, such as the custom resource attempting to release an EIP that CloudFormation is already deleting, which could fail and block stack deletion. Native resource handling is simpler and more reliable than a custom implementation.

  • Set the DeletionPolicy attribute to 'Delete' on the EIP resource

    Why this is correct

    Explicitly setting DeletionPolicy to 'Delete' on the EIP resource ensures that CloudFormation releases the Elastic IP when the stack is removed, preventing any accidental retention and associated charges. Although 'Delete' is the default policy, stating it explicitly documents the intent and guards against future changes to global defaults. This is the correct, native mechanism to guarantee the EIP is released upon stack deletion.

  • Add a DependsOn clause to ensure proper order of deletion

    Why it's wrong here

    DependsOn is used to control creation and update ordering between resources by specifying explicit dependencies, but it does not influence the order or behavior of deletion in CloudFormation. During stack deletion, resources are removed in reverse order of their creation, and DependsOn does not alter that sequence or trigger the release of the EIP. Therefore, adding a DependsOn clause would have no effect on whether the EIP is deleted, making it incorrect for this purpose.

Visual reference

Client DHCP Server 1 Discover (broadcast) 2 Offer (IP: 192.168.1.10) 3 Request (I accept) 4 Acknowledge (lease confirmed) DORA — the four-step DHCP lease process

About these practice questions

Courseiva writes every DOP-C02 question from scratch — 251 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This DOP-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DOP-C02 exam.