Glasgow were 16-3 ahead at half-time, but Roddy Grant's 59th-minute converted try and another from Tim Visser - his 48th in the RaboDirect PRO12, to equal Tommy Bowe's all-time record - drew the hosts within four points. But Townsend's men held firm to triumph.
"The pulse rate did go up," said Townsend, referring to the final quarter of the match. "Edinburgh certainly got the momentum in that last period, but I know we've got a very good defence. To get three tries was great and to get the win and retain the cup was excellent."
He added: "We know we're not the finished article. We've got a lot to work on - one is playing for 80 minutes, another is our discipline, which has got to improve.
"It's a continual process. We know we have to kick on now."
Edinburgh head coach Michael Bradley said: "Ridiculously we could've won the match, if we'd scored a try in the last minute, which would've been the greatest steal of all time.
"We got two tries in the match, but the key point for us is we were at home with 11,500 people, we needed to put Glasgow under pressure, but we ended up releasing the pressure.
"It's an easier game than we are currently playing, how we seem to be putting ourselves under pressure. We have a lot of work to do in that area.
"There's no question the boys have the ability to play rugby and when we get it right we can be very good and when we control the position with pressure we can be excellent.
"But we're not anywhere near that at the moment."