You actually kind of need to work backwards because there are usually minimum requirements on the height of the structure and the slope of the roof
In this example from San Diego, they require a minimum of 6' 8" under the beam. So you would then figure out the size of the beam (4 x 10 or whatever) and then add to it the width of the rafters that will sit on top ( 4 x 6 for example) along with your roofing material, to get the total height of the structure where your going to set the posts. Then you would apply the minimum slope of the roof (1/4" per every foot for example) and this would give you a rough idea where you would attach the ledger to your house. You could always go higher, but this would be the lowest point. I bring this up because you have that transom type window to deal with
And yes, very common to just lag bolt the ledger through the stucco to the studs. You can usually find the studs on the inside of the house using a stud finder and carefully transfer the measurements to the outside
Of course, you need to follow your local building codes, these are just examples from S Cal. Those links I gave you also show the connection details on how to attach the ledger to your house