CASE STUDY | CREYENTE INFOTECH

On-Demand Ad-hoc Environment Decommissioning with AWS Step Functions

A cost-optimized, serverless automation framework for faster environment lifecycle management

How Creyente designed a serverless, Step Functions-based framework that safely decommissions expired ad-hoc environments — orchestrating SQL cleanup, EBS volume operations, EC2 state management and duplicate protection.

100%Serverless
Up to 1yrWorkflow Runtime
ParallelSafe Execution
Scroll to explore
Overview

Faster environment lifecycle, lower cloud cost

A customer operating multiple ad-hoc development and testing environments on AWS needed a reliable way to quickly provision and decommission temporary environments on demand — used for short-term validation, testing, support activities and engineering troubleshooting.

While flexible, these environments introduced operational challenges when not decommissioned on time. Each included Auto Scaling Group resources, SQL Server databases, attached EBS volumes and supporting EC2 infrastructure — and manual cleanup risked delays, missed resources and unnecessary cost.

Objective: a quick, on-demand ad-hoc environment lifecycle framework that reduces manual effort, improves reliability and optimizes cost.

A serverless, Step Functions-based framework orchestrating SQL cleanup, EBS detach/delete, EC2 state management and environment-level duplicate protection.

The Business Challenge

Manual cleanup didn't scale

When environments reached expiry, cleanup was mostly manual and time-consuming — starting stopped Windows database servers, waiting for SQL Server and SSM connectivity, removing databases, then detaching and deleting EBS volumes. Critically, AWS Lambda's 15-minute timeout made it unsuitable for this long-running workflow.

Manual decommissioning consumed engineering time

Expired environments kept running longer than required

SQL databases and EBS volumes could remain orphaned

Cleanup spanned EC2, SQL Server, SSM, EBS and ASG metadata

A single Lambda was unreliable for long-running workflows

Duplicate triggers could process the same environment twice

Customer Impact

Before & after automation

Before

Manual, error-prone cleanup
Avoidable EBS & EC2 cost
Slow environment turnover
Orphaned databases & volumes

After

Automated, repeatable cleanup
Reduced cloud spend
Fast environment recycling
Full audit & visibility
From manual, cost-leaking cleanup to a governed, serverless decommissioning framework.
The Solution

A common Step Functions Standard Workflow

We designed a single AWS Step Functions Standard Workflow that works across all ad-hoc environments. Standard Workflows suit long-running, durable, auditable orchestration and can run for up to one year — a far better fit than Lambda for this process.

Scheduler checks environment expiry
AWS Step Functions Standard Workflow
1Prepare decommission plan
2Acquire environment lock
3Find DB EC2 instance
4Start DB instance if required
5Wait for EC2 running state
6Wait for Windows & SQL warm-up
7Wait for SSM agent online
8Run SQL database drop via SSM
9Poll SSM command status
10Find matching EBS volumes
11Detach volumes
12Wait until volumes available
13Delete volumes
14Stop DB instance if started
15Release environment lock
16Notify result
Success / Failure Notification
End-to-end orchestration: from scheduled expiry check to controlled cleanup and notification.
Key Components

How the framework is built

Common Workflow

One reusable Step Functions workflow for all environments (dev01, dev02, ...), deriving DB name, volume prefix, DB server and instance dynamically from input.

Environment-Aware Planning

A PrepareDecommissionPlan Lambda extracts the environment from the ASG name, ensuring consistent naming across database and storage cleanup.

Per-Environment Locking

A DynamoDB lock table (e.g. LOCK#dev01) prevents duplicate cleanup while allowing different environments to run in parallel.

EC2 State Management

Starts the DB server only if stopped, waits for Windows & SQL to stabilize, and stops it again afterwards to protect cost.

SSM-Based SQL Cleanup

A controlled PowerShell script via SSM Run Command drops the target database — and blocks system databases (master, model, msdb, tempdb).

EBS Volume Cleanup

Identifies volumes by environment prefix (e.g. MntVol-Remote-DEV03), detaches, waits for availability, then deletes — avoiding orphaned storage.

Safety & Design

Dry-run by default, destructive by confirmation

The framework runs in dry-run mode by default. Destructive actions require explicit confirmation flags, preventing accidental database or storage deletion.

Default (safe)

{ "dry_run": true }

Destructive (explicit)

{ "dry_run": false, "confirm_drop_database": true, "confirm_delete_volume": true }

Why Step Functions instead of a single Lambda?

Single Lambda

  • Hard 15-minute execution timeout
  • Struggles with multiple long wait states
  • Limited retry & error handling
  • No built-in execution history
VS

Step Functions

  • Long-running orchestration (up to 1 year)
  • Native wait states for EC2, SQL, SSM, EBS
  • Built-in retries & error handling
  • Full execution history & visibility
Value Delivered

A reusable, scalable automation framework

Faster Lifecycle

Expired environments cleaned up without manual intervention, enabling faster recycling for new needs.

Reduced Cloud Cost

Removes unused SQL databases and environment-specific EBS volumes after expiry.

Operational Reliability

A consistent, repeatable process: validate → lock → prepare → execute → verify → cleanup → release.

Safe Parallel Execution

Per-environment locking lets dev01, dev02 and dev03 run independently while blocking duplicates.

Audit & Visibility

A clear execution trail for every cleanup — what ran, what was targeted, and the outcome.

Low Overhead

Fully managed serverless services — no dedicated automation servers to maintain.

Built With

Managed AWS Services

A fully serverless stack keeps operational overhead low.

Step Functions Lambda Systems Manager Amazon EC2 Amazon EBS DynamoDB Secrets Manager

Want to automate your cloud environment lifecycle?

Speak to Creyente about serverless automation, cost optimization and AWS operational tooling.

Talk to our team
Write a comment
Your email address will not be published. Required fields are marked *
Scroll