Bees have a barbed sting. When they sting something with thick skin the sting will get stuck in that skin. The bee sting then pulls out of the bee and the bee will die a bit later.
Parts Of A Stinger - stinger itself (the bit that goes into you) has three parts. Apitoxin (bee-venom)- Alarm Pheromone- Histamine- Proteins- Other Components
For an animal with a brain the size of a pinhead, it is difficult to imagine they have awareness of life and death. They have self-preservation instincts yes.
No. A bee sting is barbed. The barbs must be able to stick into something that can hold the barbs tight enough that the bee will pull the sting out of its body.
From a self-preservation instinct, at some level they are aware of the fact that stinging can carry a penalty, hence they do not sting for no reason. But if they do feel the urge they sting with a sense of purpose that is quite selfless.