how to delete ec2 instance in aws through code code example
Example: delete instance from ec2
To terminate an instance
In the Amazon EC2 console, on the Instances page, locate your instance. Open the context (right-click) menu for the instance and choose Instance State, Terminate. Choose Yes, Terminate when prompted for confirmation. Amazon EC2 shuts down and terminates your instance.