Walmart is bringing FedEx shops for printing, packing and shipping into 500 of its U.S. stores, adding to the number of services it offers customers in its race against Amazon.

Walmart and FedEx have been testing the arrangement in roughly 50 locations across North Carolina, South Carolina, Virginia, Arkansas, Texas and Colorado. Following a successful pilot program, the small-format FedEx Office shops will be in 500 Walmart locations within two years, the companies announced Tuesday at the ShopTalk conference in Las Vegas.

"We gravitated toward Walmart because they have this fantastic physical infrastructure," Brian Philips, CEO of FedEx Office, told CNBC. "We are already great partners with Walmart on the transportation side, so it was natural for us to talk about a store-within-a-store format."

The Walmart-based FedEx Office locations will allow shoppers to have their packages held there for up to five business days, which can be more convenient for some customers depending on where they live, or if they're concerned about so-called porch pirates.

The companies have seen success during the test with salespeople using the locations inside Walmart to hold inventory, Philips said. For example, a medical-device company may use the shops as a storage location throughout the week instead of stowing boxes in their cars in between deliveries.

More often than not, customers have been shopping Walmart after visiting FedEx, boosting foot traffic to the store, Philips added. The printing business within Walmart has also exceeded FedEx's expectations during the test, he said.

The pint-sized shops are 450 to 750 square feet and will staffed by roughly a total of 2,000 FedEx employees.

FedEx is already a partner with Walmart for shipping. The goal of the expanded relationship within stores is to reduce some strain on fulfilling "last mile" deliveries. Amazon, Target and others have been looking for ways to do more of the same. Amazon, for example, has started placing its pickup lockers within Whole Foods stores and even malls. Target recently acquired Grand Junction and Shipt to bolster its supply chain.

"Retailers are looking at all the tools at their disposal," Philips said. "Everybody has these assets, and they are trying to figure out how to make them omnichannel," meshing online and offline commerce. "FedEx is a nice glue that holds that together."

With the FedEx Office stores inside of Walmart, shoppers will also be able to process returns there, as FedEx partners with more retailers to be able to issue refunds on the spot. Then, en masse, they will be able to ship products back to those distributors.

"It's a lot more efficient to consolidate one single delivery to or from a FedEx Office location than it is to make a dozen ... residential deliveries," Philips said.

Walmart recently surveyed its customers and found that the services they wanted most, that weren't already in stores, were packaging and shipping.

"Our busy customers view our stores as a one-stop-shop for all the products and services they are looking for," said Daniel Eckert, senior vice president of Walmart Services and Digital Acceleration.

Other services available at Walmart stores today include its MoneyCenter, where one can apply for a Walmart credit card, a vision center for eye exams, Walmart Pharmacy for prescription refills, and most recently, grocery pickup towers for online orders.

FedEx, meanwhile, is investing in expanding its retail presence across the U.S. It already has pick up and drop off locations inside retailers including Office Depot, Walgreens, Kroger and Albertsons. The partnership with Walmart is one of FedEx's most aggressive expansions in retail yet, according to Philips. It could grow to more stores, depending on how the first rollout goes, he said.