This is a frustrating experience when you are ready to cut your lawn and have made the time to do it. All you want to do is pull the cord or turn the key and get that job over with.
In most cases what you are dealing with is a fuel problem. The carburetor is not allowing fuel to pass through one of the jets and it normally is the idle jet. The main jet could also be partially plugged up or is sucking some debris into it from the carburetor float bowl.
A lack of fuel is causing starvation and the engine is dying because of it so you must get to the root of this problem to find out why. This will often require the carburetor to be taken apart and thoroughly cleaned inside and out. The ethanol in the fuel today will leave a powder like residue when it dries up and this will clog those ports. Dipping the carburetor with the plastic removed in Chemdip is one such way to clean them very well.
After you have cleaned up your carburetor, reinstall it and test your engine to see if it cures the problem with it dying right after it starts. If it does not, you may have to replace the carburetor but also check your air filter to ensure that it is not plugged with dirt and debris.