3

I'm working on a AWS CloudFormation management platform which allows users to launch, update and delete stacks on CloudFormation.

When a stack is launched, I create a DB entry to associate it with a Template (collection of resources to be created) and a Customer. Users are able to call and view the latest events happening to their stack i.e. "CREATION_IN_PROGRESS", "CREATION_COMPLETED".

Currently when a stack is deleted, I delete it from the DB immediately, providing no further information to the user aside from "Your stack is being deleted".

The callback that is currently available when executing a deleteStack() is already returned once the stack deletion is initiated.

I would like to provide more information and events whilst it is being deleted and when the stack is completely deleted, delete it from my DB.

The only way to make this happen is executing a function to check the stacks' existence on a timed interval and once it is gone, delete it from the database.

Am I wrong to assume this, or does anyone reading this have a better idea or implementation?

Any information is welcome.

Tom Nijs
  • 3,835
  • 3
  • 22
  • 40
  • 1
    You are not wrong. The only way to know when the stack has been deleted is to poll for status changes. – idbehold Oct 12 '16 at 17:38
  • Correction, he was wrong, but only since [the introduction of Waiters](https://aws.amazon.com/de/blogs/developer/waiters-in-the-aws-sdk-for-java/) in early August 2016, see more extensive answer below. – Henrik Opel Nov 07 '16 at 22:43
  • 1
    Looks like even after 5 years (oct 2021). AWS did not provide this feature. :) – Guru Oct 25 '21 at 13:25

1 Answers1

4

Polling yourself used to be the only available option, but the AWS SDK for Java 1.11.25 release introduced the com.amazonaws.waiters package, see Waiters in the AWS SDK for Java for an overview/introduction.

Note that waiters will still poll under the hood, but they abstract that logic away to offer 'convenience' API methods to wait in a blocking way via run() or in a callback oriented way via runAsync().

Regarding your explicit use case, you should look into AmazonCloudFormationWaiters.stackDeleteComplete().

Henrik Opel
  • 19,341
  • 1
  • 48
  • 64