Start with a presumption that the Gospel stories are valid history, told with a polemic, intent-to-evangelize slant. (I say this because there is some passable evidence that at least one of the two Nativity stories is pious fiction – “the Secret Origins of Jesus” à la Marvel Comics.)
Jewish tradition expected the coming of a Messiah – a man who would drive out the conquering and occupying powers and re-establish the Kingdom, and then rule righteously over Israel, cowing those potential oppressors whom he did not conquer.
According to Luke and Matthew, both of Jesus’s parents had apparitions from an angel (Gabriel, spelled out once and implied the other, IIRC) informing them that He was the kid to do that job, essentially, and that God was going to cause Mary to conceive Him without the usual babymaking technique. Note that both are descended from David – of fairly humble births themselves but “royalty” in the sense of descended from the royal family.
Various events confirm this – Mary goes and visits her elderly cousin Elizabeth, also pregnant (with John the Baptist), and is recognized as bearing the Son of the Most High; after Jesus’s birth, He is taken to the Temple and offered up in the traditional ceremony by which the firstborn is dedicated to God, and Zechariah the priest and Anna the prophetess are given prophetic insight into who He is. And three Magi (Mazdist wise men from Persia or Mesopotamia) show up to honor the newborn King of the Jews (which ticks off Herod, who thought that was his job).
So the assumption that He grew up with some awareness that He was destined to be the Messiah. As time went on, however, He recognized that what God wanted Him to do and what people’s expectations of the Messiah were, were at radical variance. Hence all the parables about “the Kingdom of God is…” – this is the guy they expect to be the restoring warrior King teaching something quite different about conquering self and making God King of your heart.
Jesus’s own awareness of what He was up to is somewhat questionable – but it’s clear that He willingly took the road that led to the Cross; there are several points where He has obvious choices and does what ends up leading Him there. John has the depiction of Jesus that is most “God-in-human-form” of the four, and he records Jesus as saying, “If I am lifted up, I will draw all men unto me” with John’s editorial comment that he was speaking of being “lifted up” on the Cross. As newcrasher notes, Eli eli lama sabachthani was a direct quote from the first verse of Psalm 22, which is eerily foreboding of what actually happened to Jesus according to the Gospels.
IMHO, Jesus, whom Scripture records as having undergone every human temptation and feeling, is here handling the “dark night of the soul” experience – the feeling of despair and total doubt of God – without which He would not have had the understanding of how a human can feel that – and conquering it by the use of that Psalm, even as He is suffering and dying.
Contrary to assumptions, Jesus did not know He’d be resurrected – He had faith that God was going to pull a cosmic rabbit out of His hat, somehow – enough faith to willingly go to the Cross in obedience to His will.