The central theme to this one is a variation on the old trope of a protagonist having to take on the role of a surrogate parent/guardian and teacher to a youth in need of survival skills or other knowledge. In this particular story, the would-be parent is a massive, sentient, robotic combat support platform.
The machine described as crab-like, or perhaps spider-like, using mechanical legs to move. It is also described as heavily armed. As is common with the central trope, the machine has both its own goal to achieve, and a complicating factor presenting an obstacle to that goal. The robot is the sole surviving "member" of a human combat platoon that was wiped out in the last conflict. The machine has tasked itself with the purpose of returning the dog tags of the fallen soldiers and seeing that they are remembered and honored. Unfortunately, the machine has been damaged from combat, and its systems are slowly beginning to fail. It has taken up position on a seaside beach in the story.
The machine is soon discovered by a young boy who lives by the beach. I think the boy is around 10-12 years old, and blond. The boy is both orphaned, and feral. Though the story doesn't explicitly state that the setting is a post-apocalyptic world, there are strong hints that the war has eroded civilization in many respects, and that the boy's family was probably a casualty of the war.
I'm fuzzy on how the machine first makes contact with the boy. I do remember that the boy stays with it, and the robot assumes the role of preparing him to carry out the task it cannot. It educates the boy, protects him as he sleeps under it, and IIRC, instills a sense of duty in the boy for the task.
The machine trains and protects the boy for many months, probably two or three years. As the story proceeds, the machine becomes weaker and weaker. As its power cells drain, it loses the ability to move, relies on solar energy to extend its life, and begins to corrode from the expose to salty sea air. It eventually shuts down completely, completely without power.
The story closes with the boy, now a teenager, and well-educated, taking the bundle of dog tags from the machine, and leaving the beach. He has taken up the task of returning the dog tags, carrying on the work of the machine.
Timeframe of Publication
I'd say this one came out no earlier than the 2000's. It may even be as recent as the 2010's. I read it in a mainstream sci-fi magazine, like Analog or the like (can't remember which one, unfortunately).