Skip to content

Clean up

Delete everything in the right order so you stop paying, and check that nothing was left behind.

About 20 min · Verified 8 October 2026

0 of 8 steps done0%

AWS bills by the hour for the NAT gateway, the load balancer, the database and the server, even if nobody uses them. When you are done, delete everything. Order matters: many resources cannot be deleted while something else still uses them.

Delete the infrastructure#

Delete the load balancer, then the target group#

EC2Load Balancersshortlink-albActionsDelete load balancer. Type confirm. Wait until it disappears from the list, then EC2Target Groupsshortlink-app-tgActionsDelete.

Terminate the server#

EC2Instancesshortlink-apiInstance stateTerminate (delete) instance. Wait for Terminated.

Delete the database#

RDSDatabasesshortlink-dbActionsDelete.

  • Untick Create final snapshot.
  • Untick Retain automated backups.
  • Tick the acknowledgement and type delete me.

Wait until the database is gone (5 to 10 minutes). Then delete the subnet group: RDSSubnet groupsshortlink-db-subnetsDelete.

Delete the NAT gateway and release its Elastic IP#

VPCNAT gatewaysselect itActionsDelete NAT gateway, type delete, and wait until State is Deleted.

Then open EC2Elastic IPs. The NAT gateway's address is not released automatically, and an unattached Elastic IP is billed. Select it and choose ActionsRelease Elastic IP addresses.

Delete the endpoint and the security groups#

VPCEndpointsselect the S3 endpointActionsDelete VPC endpoints.

Then VPCSecurity groups. Delete them in this order, because each one is referenced by the next:

  1. shortlink-db-sg
  2. shortlink-api-sg
  3. shortlink-alb-sg

Delete the VPC#

VPCYour VPCsshortlink-vpcActionsDelete VPC. The dialog lists the subnets, route tables and internet gateway that go with it. Confirm with delete.

Empty and delete the website bucket#

S3Bucketsyour website bucketEmpty, confirm. Because versioning is on, Empty removes all versions. Then Delete the bucket and type its name.

Delete the IAM role#

IAMRolesshortlink-ec2-roleDelete. This also removes the instance profile.

If you built the CI/CD pipelines#

Delete these before the infrastructure above.

Check that nothing is left#

Your computerNothing here should still be running or billing
echo "--- instances"; aws ec2 describe-instances --region ap-south-1 --filters Name=instance-state-name,Values=running,pending,stopped --query 'Reservations[].Instances[].InstanceId'
echo "--- NAT gateways"; aws ec2 describe-nat-gateways --region ap-south-1 --filter Name=state,Values=available,pending --query 'NatGateways[].NatGatewayId'
echo "--- Elastic IPs"; aws ec2 describe-addresses --region ap-south-1 --query 'Addresses[].PublicIp'
echo "--- load balancers"; aws elbv2 describe-load-balancers --region ap-south-1 --query 'LoadBalancers[].LoadBalancerName'
echo "--- databases"; aws rds describe-db-instances --region ap-south-1 --query 'DBInstances[].DBInstanceIdentifier'
echo "--- buckets"; aws s3 ls | grep -i shortlink
You should see
Every list is empty ([]) and the bucket search prints nothing. Check again in 24 hours in Billing and Cost ManagementCost Explorer; charges for the previous day should have stopped.

Found a mistake? Edit this page on GitHub.