AWS Solutions Architect Project (Cost Optimization Pillar) – Automated Cost Management – Part 4

In this final part, we will execute the CostManager cleanup automation, which helps identify and remove unused AWS resources, such as unattached EBS volumes, un-associated Elastic IPs, and optionally **idle EC2 instances,**to reduce unnecessary spend. We’ll also apply S3 lifecycle policy to automatically transition old objects to cheaper storage tiers over time. All steps prioritize cost optimization and manual control through approval-based workflows.

Step 1: Execute the Automation Document

  • Go to AWS Systems Manager console, select Document
  • Locate CostManager-Cleanup document, click Execute Automation
  • Select Simple execution to manually review all actions
  • Fill the input parameters
    • AutomationAssumeRole: Leave as CostManager-AutomationRole
    • Approver: Enter the IAM role’s ARN subscribed to the CostManagerAlerts SNS topic to receive approval requests.
  • Click Execute
  • The automation workflow will start and it will pause at ApproveDeletion step as per flow chart above
  • Return back to AWS Systems Manager console, select Automation, select Executions
  • Then select the running execution, click Actions, then select Approve/Deny
  • Logout from AWS console and login again as the Approver IAM user (not root), we can click Approve to proceed

Then the automation should be working well as per below screenshot where it shows all deletion and email notification (via SNS) have been sent right after the steps are completed

Finally we shall do the manual verification on EC2 console if the deletion has been completed

  • Go to EC2 console, select Volumes
  • Verify the unattached volumes marked by automation are no longer exist. As we can see below, only the volumes with in-use state are exist
  • Next, select Elastic IPs from the sidebar menu
  • Verify there is no more unassigned elastic IP

Step 2: Manually Remove Idle EC2 Instances

The automation that we triggered doesn’t automatically terminate idle EC2 instances. Because Automation only removes unused EBS volumes and Elastic IPs. Stopped or idle EC2 instances still incur costs for storage or reserved capacity, so manual deletion ensures maximum cost savings. Therefore, we need to review and delete them manually.

  • Go to EC2 Console, select Instances
  • Select the instances generated via CloudFormation
  • Select Instance State, choose Terminate

Step 3: Apply S3 Lifecycle Policy

Same like EC2 instances which are not automatically removed by the automation workflow, S3 buckets are also required a manual removal handling. Instead of removing the bucket, in this project we will choose another use case example to move the file into the cheaper storage class so after certain period of time it can reduce the S3 costs over the time.

  • Go to S3 Console, select our bucket, select Management, click Lifecycle Rules
  • Click Create Lifecycle Rule and give it name: MoveOldFilesToGlacier
  • Scope: Apply to all objects in the bucket
  • Lifecycle Rule Actions: Select Transition current versions of objects between storage classes (required).
  • Set Transition Actions:
    • Click Add transition under Current versions:
      • Days after object creation: 30
      • Storage class: S3 Standard-IA (Infrequent Access)
    • Click Add transition again:
      • Days after object creation: 90
      • Storage class: S3 Glacier Flexible Retrieval
  • Click Create rule

This rule automatically moves rarely accessed files to cheaper storage classes and optionally deletes very old files, reducing long-term S3 costs without manual effort. For this project scope, we can also removes the bucket once we see the files moved to the lower S3 tier storage.


Project Conclusion

We have now built a real-world cost-control system that detects unused resources, sends alerts, and automates cleanup, securely and with approval. This hands-on project reflects the Cost Optimization pillar of the AWS Well-Architected Framework.


Resources Cleanup

To avoid ongoing AWS charges, remember to delete what we created:

  1. Since CloudFormation cannot delete non-empty S3 buckets, we need to manually remove it.
    • Go to S3 Dashboard
    • Locate the bucket created by the CloudFormation stack (costmanager-frontend)
    • Empty the bucket and delete the bucket
  2. Delete the CloudFormation stack
    • Go to CloudFormation Console
    • Select the stack we deployed (e.g., CostManager-for-Wasteful-Infra)
    • Click Delete Stack and confirm
      • This will automatically delete EC2 instances, launch template, volumes, and elastic IP
  3. Review and delete CloudWatch logs
    • Go to CloudWatch, select Log Management
    • Check for logs created by EC2 instances or the ALB Optionally and delete them
  4. Review billing dashboard
    • Go to Billing and Cost Management console, select Cost Explorer
    • Filter by service or tag (if tagging was enabled)
    • Ensure there are no ongoing charges from unused resources