From the snopes entry on this story:
Origins: In April 2012, 12-year-old Cody Green, who had been battling leukemia since he was 22 months old, finally succumbed to a fungus that attacked his brain. According to news accounts, Cody had "always admired the strength and courage of the Marines," and so in his final days members of the Marines made him an honorary member of the United States Marine Corps: Members of the Marines decided to step in and do something.
"They decided Cody, with the strength and honor and courage he showed through the whole thing, he should be a Marine," said Cody's father David Snowberger.
Cody was given Marine navigator wings and was made an honorary member of the United States Marine Corps.
One Marine, Sergeant Mark Dolfini, went even further to honor Cody and, during the boy's final night, stood guard outside his hospital door all night long until Cody passed away: Sergeant Mark Dolfini heard of Cody Green's situation through his co-worker, and got in contact with Cody's parents. When the call came that Cody was passing, he took action.
"I got the call from [his father] David about 3:00 or 4:00 that afternoon," said Sgt. Dolfini. "He made it pretty clear to me that he was terminal and he wasn't going to last too much longer. I thought this is something that needs to happen right away."
"When I was driving down there, I had no idea what I was going to say, I had no idea what I was walking into, I didn't know if Cody was conscious," said Sgt. Dolfini. "I didn't know anything. I didn't know what I was walking into whatsoever."
When Sgt. Dolfini arrived, Cody was not awake.
"He was not conscious, " said Sgt. Dolfini. "I mean, if he was, he was not responsive but he was heading to a better place."
Sergeant Dolfini made the decision to stand guard outside Cody's door for as long as Cody was alive, which turned out to be eight straight hours. When a nurse told Sgt. Dolfini Cody's time was limited, Sgt. Dolfini made the choice to say goodbye.
He presented Cody with his navigator wings and let his family be with him in his final moments.
Sergeant Dolfini said leaving Cody and his family was not one of the hardest thing he's ever done. That moment came a week later when he attended Cody's funeral.
"I went and went in front of the casket and saluted Cody," said Sgt. Dolfini. "I turned and before I left I stopped and I turned right to Tracy, Cody's mother. We looked straight into each other's eyes and I saluted her and that was so hard. That was the most difficult thing I've encountered in awhile, but I know for that moment in time that we were locked in each other's gaze, keeping your bearing at that point is a tough thing to do."
"Marines don't do this sort of thing for acclaim," said Sgt. Dolfini. "That's not how we're wired. It's not why we join. We didn't join the Marine Corps. to be rich, we didn't join it for fame, you don't do it for that reason."
"If we all did just something like that once a day or just something small just think of what an incredible legacy that would leave for Cody," said Sgt. Dolfini.
Sergeant Dolfini said he has spoken with Cody's family several times since his funeral. He said they will be friends for life.