Overview
This comprehensive guide will help you systematically delete all AWS resources created during the serverless media processing pipeline project to avoid ongoing charges. It’s critical to follow the deletion order to prevent errors caused by dependencies between resources.
What you’ll learn:
- Proper resource deletion order
- Cost verification techniques
- Billing alert setup
- Emergency cleanup procedures
- Resource monitoring strategies
Region: ap-south-1 (Mumbai)
Estimated Cleanup Time: 15-20 minutes
Prerequisites: Parts 1 & 2 completed
Table of Contents
- Important Notes Before Starting
- Deletion Order Summary
- Step-by-Step Cleanup Process
- Cost Verification
- Emergency Procedures
- Best Practices
- Troubleshooting
Important Notes Before Starting
⚠️ Critical Warnings
- Deletion is permanent - Once deleted, resources cannot be recovered
- Follow the order - Some resources depend on others and must be deleted in sequence
- Verify each step - Check that resources are fully deleted before moving to the next step
- Check your AWS bill - After cleanup, verify no charges are accumulating in the Billing Console
📋 Pre-Cleanup Checklist
Before starting cleanup, ensure you have:
Deletion Order Summary
The correct deletion order is crucial to avoid dependency errors:
- S3 Event Notifications (stop triggers)
- SQS Queue Messages (purge queues)
- Lambda Functions (remove processing logic)
- API Gateway API (remove public endpoints)
- S3 Bucket Contents (empty buckets)
- S3 Buckets (delete storage)
- DynamoDB Table (remove data store)
- SQS Queues (remove message queues)
- CloudWatch Log Groups (clean up logs)
- Lambda Layers (remove dependencies)
- IAM Roles and Policies (clean up permissions)
Step-by-Step Cleanup Process
Step 1: Delete S3 Event Notifications
Why first: Prevents new Lambda invocations while we’re cleaning up
1.1 Navigate to S3
- AWS Console → Search “S3” → Click S3
1.2 Open Uploads Bucket
- Click on
amodhbh-media-uploads
1.3 Delete Event Notification
- Go to Properties tab
- Scroll to Event notifications
- Find
trigger-dispatcher-on-upload - Click on it → Click Delete
- Confirm deletion
1.4 Verify
- Event notifications section should be empty or show “No event notifications”
Step 2: Purge SQS Queues
Why before deleting Lambda: Prevents messages from being processed during cleanup
2.1 Purge Main Queue
Navigate to SQS:
- AWS Console → Search “SQS” → Click Simple Queue Service
Purge processing queue:
- Select
media-processing-queue (checkbox) - Click Purge
- Type
purge to confirm - Click Purge
- Wait for confirmation message
2.2 Purge Dead Letter Queue
Purge DLQ:
- Select
media-processing-dlq (checkbox) - Click Purge
- Type
purge to confirm - Click Purge
Verify:
- Both queues should show “Messages available: 0”
Step 3: Delete Lambda Functions
Order matters: Delete in this sequence to avoid errors
3.1 Delete Worker Lambda
Navigate to Lambda:
- AWS Console → Search “Lambda” → Click Lambda
- Click Functions in left sidebar
Delete worker-lambda:
- Select
worker-lambda (checkbox) - Click Actions → Delete
- Type
delete to confirm - Click Delete
3.2 Delete Dispatcher Lambda
- Delete dispatcher-lambda:
- Select
dispatcher-lambda (checkbox) - Click Actions → Delete
- Type
delete to confirm - Click Delete
3.3 Delete API Lambda Functions
Delete request-upload-lambda:
- Select
request-upload-lambda (checkbox) - Click Actions → Delete
- Type
delete to confirm - Click Delete
Delete get-job-status-lambda:
- Select
get-job-status-lambda (checkbox) - Click Actions → Delete
- Type
delete to confirm - Click Delete
3.4 Verify
- Lambda functions list should not show any of these functions:
worker-lambdadispatcher-lambdarequest-upload-lambdaget-job-status-lambda
Step 4: Delete API Gateway API
4.1 Navigate to API Gateway
- AWS Console → Search “API Gateway” → Click API Gateway
4.2 Delete the API
- Find
media-processing-api - Select it (checkbox)
- Click Actions → Delete
- Type the API name to confirm:
media-processing-api - Click Delete
4.3 Verify
- API should no longer appear in the APIs list
Step 5: Empty S3 Buckets
Critical: S3 buckets MUST be empty before they can be deleted
5.1 Empty Uploads Bucket
Navigate to S3:
- AWS Console → Search “S3” → Click S3
Empty uploads bucket:
- Find
amodhbh-media-uploads - Select it (checkbox, NOT click on name)
- Click Empty
- Type
permanently delete to confirm - Click Empty
- Wait for “Successfully emptied” message
- Click Exit
5.2 Empty Processed Bucket
- Empty processed bucket:
- Find
amodhbh-media-processed - Select it (checkbox)
- Click Empty
- Type
permanently delete to confirm - Click Empty
- Wait for completion
- Click Exit
5.3 Verify
- Both buckets should show “0 objects”
Step 6: Delete S3 Buckets
Now that buckets are empty, we can delete them.
6.1 Delete Uploads Bucket
- In S3 console:
- Select
amodhbh-media-uploads (checkbox) - Click Delete
- Type the bucket name to confirm:
amodhbh-media-uploads - Click Delete bucket
6.2 Delete Processed Bucket
- Delete processed bucket:
- Select
amodhbh-media-processed (checkbox) - Click Delete
- Type the bucket name to confirm:
amodhbh-media-processed - Click Delete bucket
6.3 Verify
- Neither bucket should appear in your S3 buckets list
Step 7: Delete DynamoDB Table
7.1 Navigate to DynamoDB
- AWS Console → Search “DynamoDB” → Click DynamoDB
- Click Tables in left sidebar
7.2 Delete the Table
- Select
media-processing-jobs (checkbox) - Click Delete
- Deselect “Create a backup of this table” (to avoid charges)
- Type
delete to confirm - Click Delete table
7.3 Verify
- Table status will show “Deleting” then disappear from the list
- This may take 1-2 minutes
Step 8: Delete SQS Queues
8.1 Delete Main Queue
Navigate to SQS:
- AWS Console → Search “SQS” → Click Simple Queue Service
Delete processing queue:
- Select
media-processing-queue (checkbox) - Click Delete
- Type
delete to confirm - Click Delete
8.2 Delete Dead Letter Queue
- Delete DLQ:
- Select
media-processing-dlq (checkbox) - Click Delete
- Type
delete to confirm - Click Delete
8.3 Verify
- Both queues should no longer appear in the queues list
Step 9: Delete CloudWatch Log Groups
Lambda functions automatically create log groups in CloudWatch. These can accumulate charges over time.
9.1 Navigate to CloudWatch
- AWS Console → Search “CloudWatch” → Click CloudWatch
- Left sidebar → Logs → Log groups
9.2 Delete Log Groups
Delete log groups for each Lambda function:
- Find and delete these log groups (one at a time):
/aws/lambda/worker-lambda/aws/lambda/dispatcher-lambda/aws/lambda/request-upload-lambda/aws/lambda/get-job-status-lambda
For each log group:
- Select it (checkbox)
- Click Actions → Delete log group(s)
- Click Delete
9.3 Verify
- None of these log groups should remain in the list
Step 10: Delete Lambda Layers
10.1 Navigate to Lambda
- AWS Console → Search “Lambda” → Click Lambda
- Left sidebar → Layers
10.2 Delete Pillow Layer
- Click on
pillow-layer - For each version listed:
- Click the version number
- Click Delete (if available)
Note: If delete is not available, this is fine. Layers with no associated functions don’t incur charges.
Step 11: Delete IAM Roles and Policies
Why last: Ensures no resources are still using these roles
11.1 Delete Worker Lambda Role
Navigate to IAM:
- AWS Console → Search “IAM” → Click IAM
- Left sidebar → Roles
Delete media-worker-lambda-role:
- Search for
media-worker-lambda-role - Select it (checkbox)
- Click Delete
- Type the role name to confirm
- Click Delete
11.2 Delete API Lambda Role
- Delete media-api-lambda-role:
- Search for
media-api-lambda-role - Select it (checkbox)
- Click Delete
- Type the role name to confirm
- Click Delete
11.3 Delete Dispatcher Lambda Role
- Delete dispatcher-lambda-role:
- Search for
dispatcher-lambda-role - Select it (checkbox)
- Click Delete
- Type the role name to confirm
- Click Delete
11.4 Verify
- None of these roles should appear in your IAM roles list:
media-worker-lambda-rolemedia-api-lambda-roledispatcher-lambda-role
Cost Verification
Step 1: Final Verification
1.1 Resource Checklist
Go through each service and verify no project resources remain:
S3:
Lambda:
API Gateway:
DynamoDB:
SQS:
CloudWatch Logs:
IAM:
Step 2: Check AWS Billing
It’s important to verify that cleanup was successful by checking your AWS bill.
2.1 View Current Charges
Navigate to Billing:
- Click your account name (top-right)
- Click Billing and Cost Management
Check costs:
- Click Bills in left sidebar
- View current month charges
- Look for these services (should be $0 or minimal):
- Amazon S3
- AWS Lambda
- Amazon DynamoDB
- Amazon API Gateway
- Amazon SQS
2.2 Set Up Billing Alerts (Recommended)
To prevent unexpected charges in the future:
In Billing Console:
- Left sidebar → Billing preferences
- Enable Receive Billing Alerts
- Save preferences
Create CloudWatch Alarm:
- Go to CloudWatch console
- Left sidebar → Alarms → All alarms
- Click Create alarm
- Select metric → Billing → Total Estimated Charge
- Set threshold (e.g., $5)
- Configure email notification
- Create alarm
Step 3: Cost Verification Timeline
After completing cleanup:
- Immediate: Most resources stop incurring charges
- 24 hours: Check billing to ensure no new charges
- 7 days: Verify final bill for the month
- 30 days: Confirm no recurring charges on next month’s bill
Emergency Procedures
If you’re seeing unexpected high charges:
- Delete all S3 buckets immediately (empty them first)
- Delete all Lambda functions
- Delete API Gateway APIs
- Purge and delete all SQS queues
- Delete DynamoDB tables
- Open a support ticket in AWS Console explaining the situation
- Contact AWS Billing Support (available even on free tier)
Emergency Cleanup Script
For rapid cleanup, you can use AWS CLI (if configured):
# Delete Lambda functions
aws lambda delete-function --function-name worker-lambda
aws lambda delete-function --function-name dispatcher-lambda
aws lambda delete-function --function-name request-upload-lambda
aws lambda delete-function --function-name get-job-status-lambda
# Delete S3 buckets (must be empty first)
aws s3 rb s3://amodhbh-media-uploads --force
aws s3 rb s3://amodhbh-media-processed --force
# Delete DynamoDB table
aws dynamodb delete-table --table-name media-processing-jobs
# Delete SQS queues
aws sqs delete-queue --queue-url https://sqs.ap-south-1.amazonaws.com/YOUR_ACCOUNT/media-processing-queue
aws sqs delete-queue --queue-url https://sqs.ap-south-1.amazonaws.com/YOUR_ACCOUNT/media-processing-dlq
Best Practices
1. Resource Tagging
Always tag your resources for easy identification:
{
"Project": "serverless-media",
"Environment": "production",
"Owner": "your-email@example.com",
"CostCenter": "engineering"
}
2. Cost Monitoring
Set up comprehensive cost monitoring:
- Billing Alerts: Multiple thresholds ($5, $25, $50)
- Cost Explorer: Regular analysis of spending patterns
- Resource Groups: Organize resources by project
- CloudWatch Dashboards: Visual cost monitoring
3. Cleanup Automation
Consider using Infrastructure as Code (IaC) for easier cleanup:
- AWS CDK: TypeScript/Python infrastructure
- Terraform: Multi-cloud infrastructure
- CloudFormation: AWS-native templates
4. Resource Lifecycle Management
Implement lifecycle policies:
- S3 Lifecycle: Automatic deletion of old files
- DynamoDB TTL: Automatic cleanup of expired items
- Lambda Logs: Automatic log retention policies
Troubleshooting
Common Issues and Solutions
Cannot delete S3 bucket - “Bucket not empty”
Solution:
- Go back to Step 5 and empty the bucket again
- Check if versioning is enabled (if so, you need to delete all versions)
- In bucket → Properties → Bucket Versioning
- If enabled, go to bucket, toggle “Show versions”, select all, delete
Cannot delete SQS queue - timeout error
Solution:
- Wait 60 seconds after purging before attempting deletion
- Refresh the page and try again
Cannot delete IAM role - “Role is being used”
Solution:
- A resource is still using this role
- Go back and verify all Lambda functions are deleted
- Wait 5 minutes for AWS to propagate the deletion
- Try deleting the role again
Cannot delete Lambda function - “Function is being invoked”
Solution:
- Ensure S3 event notifications are deleted (Step 1)
- Wait a few minutes for in-flight executions to complete
- Try deletion again
CloudWatch Log Groups keep appearing
Solution:
- Log groups are recreated if Lambda functions are invoked
- Ensure Lambda functions are deleted first
- Delete log groups after Lambda deletion
- If they reappear, you may have another Lambda with the same name
Advanced Troubleshooting
Check for Hidden Resources
Check all regions:
- Change region in AWS Console
- Look for resources in other regions
Check CloudFormation stacks:
- Look for any stacks that might have created resources
- Delete stacks if found
Check AWS Config:
- Review configuration history for any missed resources
Resource Dependencies
Some resources have hidden dependencies:
- Lambda Layers: May be referenced by other functions
- IAM Policies: May be attached to multiple roles
- S3 Bucket Policies: May have complex access rules
- VPC Endpoints: May be used by other services
Additional Cleanup (Optional but Recommended)
Delete CloudShell Files
If you used CloudShell to create the Pillow layer:
- Open CloudShell
- Run:
rm -rf pillow-layer/ - Close CloudShell
Check Other Regions
If you accidentally created resources in another region:
- In AWS Console, change region (top-right dropdown)
- Check each service in other regions
- Delete any project resources found
Review Cost Explorer
- Go to Cost Explorer in Billing Console
- View costs by service for the past month
- Identify any unexpected charges
- Investigate and clean up if needed
What If I Want to Rebuild?
If you want to recreate this project later:
- All the Phase guides (1-4) contain complete instructions
- You can reuse the same bucket names (if globally available)
- All code is preserved in the markdown files
- The entire setup takes approximately 2-3 hours
Quick Rebuild Checklist
Summary
After completing this cleanup guide, you should have:
✅ Deleted all project-related AWS resources
✅ Verified $0 (or minimal) ongoing charges
✅ Learned the correct order for resource deletion
✅ Set up billing alerts to prevent future surprises
Estimated time to complete cleanup: 15-20 minutes
Final Checklist
Before considering cleanup complete:
Questions?
If you encounter issues during cleanup:
- Check the troubleshooting section above
- Review AWS documentation for specific services
- Use AWS re:Post (AWS community forum) for technical questions
- Contact AWS Support if charges continue after cleanup
Cleanup Complete! 🎉
You’ve successfully removed all resources from your serverless media processing pipeline. Your AWS account is now clean, and you won’t incur ongoing charges for this project.
If you learned valuable skills from this project, consider building more serverless architectures - they’re cost-effective, scalable, and represent the future of cloud computing!
Resource Summary Table
| Service | Resource Name | Monthly Cost (Idle) | Monthly Cost (Active) | Deletion Step |
|---|
| S3 | amodhbh-media-uploads | $0 | $0.023/GB | Step 5-6 |
| S3 | amodhbh-media-processed | $0 | $0.023/GB | Step 5-6 |
| DynamoDB | media-processing-jobs | $0 | ~$0.01 | Step 7 |
| SQS | media-processing-queue | $0 | ~$0.01 | Step 8 |
| SQS | media-processing-dlq | $0 | $0 | Step 8 |
| Lambda | worker-lambda | $0 | ~$0.10 | Step 3 |
| Lambda | dispatcher-lambda | $0 | ~$0.01 | Step 3 |
| Lambda | request-upload-lambda | $0 | ~$0.01 | Step 3 |
| Lambda | get-job-status-lambda | $0 | ~$0.01 | Step 3 |
| API Gateway | media-processing-api | $0 | ~$0.01 | Step 4 |
| CloudWatch | Log Groups | $0 | ~$0.01 | Step 9 |
| TOTAL | | $0.00 | ~$0.20 | All Steps |
Active costs based on 1000 operations/month estimate
This is Part 3 of a 4-part series on building a production-ready serverless media processing pipeline. You’ve now completed the entire series and have the knowledge to build, deploy, and clean up serverless architectures on AWS!