The very question ‘Does prayer work?’ puts us in the wrong frame of mind from the outset. ‘Work’: as if it were magic, or a machine—something that functions automatically. ...Somehow reflecting on that passage changed the way I feel about petitionary prayer. It is an action like other actions I might take. It is supernatural action, but it is putting ourselves to some trouble nonetheless. I have prayed my petitions like anyone else, but I haven't (I think) taken my own part in them seriously enough.
Petitionary prayer is, nonetheless, both allowed and commanded to us: “Give us our daily bread.” And no doubt it raises a theoretical problem. Can we believe that God ever really modifies His action in response to the suggestions of men?
It is not really stranger, nor less strange, that my prayers should affect the course of events than that my other actions should do so. They have not advised or changed God’s mind—that is, His over-all purpose. But that purpose will be realized in different ways according to the actions, including the prayers, of His creatures.
For He seems to do nothing of Himself which He can possibly delegate to His creatures. He commands us to do slowly and blunderingly what He could do perfectly and in the twinkling of an eye. He allows us to neglect what He would have us do, or to fail. Perhaps we do not fully realize the problem, so to call it, of enabling finite free wills to coexist with Omnipotence ...
C.S. Lewis, The World’s Last Night and Other Essays
It goes hand-in-hand with something that Matt Fradd said on the Pints with Aquinas podcast. Answering a similar question, St. Thomas said that perhaps God has so ordered some events that the only action it takes is our prayer to make things tip one way or the other. Happen or not happen.
Both those thoughts taken together have, as I said, changed how I think about prayer. My prayers matter. It is not all just in God's hands. He invites us to participate also in the creation of miracles.