OCHERETYNE, Ukraine—When Ukrainian Sgt. Andriy Kuprianov called in an artillery strike on a group of Russian soldiers in Avdiivka one recent night, he got back bad news: Not enough ammo .

It is a familiar episode on the second anniversary of Russia’s full-scale invasion, with Ukraine on the defensive amid shortages of military personnel and ammunition in a war that has killed and maimed hundreds of thousands on both sides. Helped by incremental gains, like the one Kuprianov couldn’t stop, Russia last week captured the eastern city of Avdiivka , its first significant advance in nine months.

“You see the enemy, but you simply can’t strike it,” said the 26-year-old, echoing a frustration voiced by Ukrainian troops all along the 900-mile front line.

Ukraine is marking the anniversary of Russia’s full-scale invasion with a mixture of defiance and trepidation, with a bill on further aid to Ukraine stuck in Congress and Russian forces pressing hard in several places along the front line.

Russia also faces challenges and is losing masses of troops and equipment in suicidal assaults . Ukraine has had success striking high-value Russian targets, downing eight warplanes in recent days and, early Saturday, using explosive drones to damage a major steel factory in Russia that supplies the military, according to Ukrainian officials.

In a defiant message posted on social media Saturday, Ukrainian President Volodymyr Zelensky hailed the bravery and resilience of Ukraine’s troops in resisting Russian invaders.

Ukraine’s main task is to defend, Zelensky said in an interview with Fox News last week. But he promised “some surprises” for Russia and noted successes in striking Russian warships in the Black Sea.

“And, of course, we will prepare a new counteroffensive,” he said.

The U.S. is also facing an inflection point. The Biden administration pledged long-term help to Ukraine, but an additional aid package has stalled in the Republican-led House . Leading a Democratic delegation to Ukraine, Senate Majority Leader Chuck Schumer said that if Congress fails to pass the latest aid package, Ukraine could lose the war.

“The United States and our people and the American people will pay a price diplomatically, politically, economically and militarily for decades,” Schumer said in an interview.

The second year of the war was disappointing for Ukraine. After repelling the Russian assault on Kyiv and taking back swaths of territory in 2022, Ukraine failed to make significant gains in a major counteroffensive last year. Now, it is largely reliant on military equipment provided by the West and is struggling to replenish its battered army with fresh troops.

The Russians are inching forward on land, but Ukraine has had more success in the air and at sea, as well as striking deep in the Russian rear. Ukraine said on Friday it had downed an advanced A-50 military spy plane that supplied targets for Russian jet fighters and helped Moscow’s forces detect and strike Ukrainian air defenses along the front line. Ukraine says it was the second such plane it has downed in recent weeks.

Ukraine has also used naval drones to strike Russian warships and force them away from its Black Sea coast, allowing exports from its main port of Odesa to restart. And regular Ukrainian drone strikes on oil facilities and infrastructure deep inside Russia have disrupted Moscow’s supply lines. Ukrainian officials said their drones early Saturday struck a major steel plant in Lipetsk, hundreds of miles from the border with Ukraine, which they called a legitimate target as it manufactures steel for military use.

Russia, which has a much larger population, has placed its economy on a war footing and its vast military-industrial complex is churning out artillery shells and rockets. President Vladimir Putin still wants to bring Ukraine under his control, but the goal appears distant.

Western officials and military analysts say that Ukraine could use this year to wear down Russia’s combat strength while rebuilding its own forces with Western training and support, before launching another counteroffensive against a weakened opponent in 2025.

“Russia holds the material advantages and much of the initiative along the front,” said Michael Kofman, a senior fellow at the Carnegie Endowment for International Peace, a Washington, D.C.-based think tank. “But the Russian military can’t afford to fight that many Avdiivkas in 2024 given how much equipment they lost in that battle.”

This is part of the reason why, according to Ukrainian officials, the fight for Avdiivka was strategically beneficial to Ukraine. Open-source intelligence analysts say Russia lost hundreds of armored vehicles in its final assault on the city, and thousands of lives. As Ukraine shifts to defense, soldiers and military officials say it can bleed and grind down the Russians when they go on the offensive against well-prepared Ukrainian positions.

“We couldn’t hold on to Avdiivka, but it was the perfect place in which to bury a lot of Russians into the earth,” said a junior sergeant operating a U.S.-supplied Bradley Fighting Vehicle outside Ocheretyne, a village near Avdiivka.

The 29-year-old goes by the call sign Zenit, taken from the name of a former military base in Avdiivka that became a key position for Ukrainian forces. He was first stationed there in 2015, a year after Russian paramilitaries’ first assaults on the city.

Ukrainian forces held off Russia for so long in Avdiivka that the warehouses of the industrial zone where they had their military positions were adorned with marble plaques placed by soldiers to commemorate comrades who have died there since 2014 when Russia first invaded eastern Ukraine.

After losing much of its professional military, Ukraine is in dire need of recruits . Controversial legislation, which cuts the draft age from 27 to 25, limits options for deferral and increases penalties for evasion, is expected to face a decisive vote in parliament in the coming weeks. But it has been retracted and revised several times, and may not pass in its current form.

“The mobilization law is an important bellwether of Ukraine’s will to continue this war,” said Kofman, the analyst. “Either they get more men or it’s not clear how they’re going to sustain this war.”

Two years of Russia’s full-scale invasion have transformed Ukrainian society. Millions have fled the country, and many remain abroad despite a government campaign to bring them home so they can support the economy with their taxes and labor. Thousands of soldiers, many of whom held mundane jobs two years ago, now treat military service as a lifestyle and struggle to see beyond it.

“I’m so used to war that I can no longer imagine civilian life,” said Lt. Oleksandr Kruhlik, who worked as a cameraman for an entertainment TV show before he joined the military after Russia invaded. “I have my own military family now.”

The war has also turned swaths of the country into a landscape of destroyed towns and villages where a tiny proportion of the prewar population—mostly elderly residents and the few who await a Russian victory—lives despite disrupted water or electricity supplies, in buildings damaged by bombardment.

Across a front line stretching from the southern Kherson region to the Kharkiv region in the northeast, excavators are now carving out new trenches as Ukrainian troops dig in. Russia’s capture of Avdiivka places a renewed focus on Pokrovsk, a town of 60,000 residents to the west that has become a refuge for residents fleeing front-line villages and is now set to become a military hub too.

In villages close to Avdiivka, residents who remain say Russia has stepped up its attacks, dropping bombs with 230 kilograms of explosives to destroy what is in its path.

“We used to be a good distance from the front,” said Oleksandr Momot, a civil protection officer responsible for infrastructure and safety in Ocheretyne, where only 400 residents remain. “Since Avdiivka fell we’re being hit with mortars and even tank fire, and feel the Russians getting closer.”

“On the eve of the war’s two-year anniversary, I feel only anger,” he said.

Ocheretyne was once a thriving commuter town of 5,000 people, many of whom traveled for work to the nearby city of Donetsk, now under Russian occupation. Momot, a 32-year-old native of the town, struggles to comprehend how it could have deteriorated so fast. Today, stray cats and dogs roam the mostly deserted streets, as civilians hide in bomb shelters and basements.

Kuprianov, who led a unit from Ukraine’s 3rd Assault Brigade into Avdiivka last week, said Ukraine’s resistance against Russia protected all of Europe, not just Ukraine.

“Russia is an enemy of the West just as much as ours. But it’s us who are currently fighting with it,” he said. “The West’s logic should be to provide us with everything we need, because we are fighting a common enemy.”

With or without further U.S. aid, he said he and his men have no choice but to fight on.

“We’ll fight as long as it takes,” Kuprianov said. “Two more years, or 20 more. We’ll keep going because we know the price of failing to do so.”

Write to Matthew Luxmoore at matthew.luxmoore@wsj.com