A CVS Pharmacy store is seen in the Manhattan borough of New York City, New York, U.S., November 30, 2017.

CVS Health is rolling out delivery for prescription drugs — before Amazon.

Customers will appreciate it, CVS believes, but it's clear the move is an attempt to stay ahead of Amazon. The e-commerce giant's possible entry into the space has kept drugstores on edge, but it's inaction so far has given them time to prepare.

Customers in most markets where CVS' nearly 10,000 stores are located will be able to receive their orders either one or two days after placing them. Some customers in urban markets will be able to receive orders the same day.

Amazon has already strained retailers with its free two-day shipping and is now eyeing the prescription drug market. CVS' program will be a test of whether patients are willing to wait for their medicines in exchange for the convenience of delivery.

"The rollout of delivery from nearly all of our 9,800 retail pharmacy locations nationwide represents another step forward for us in delivering innovative omnichannel solutions that help people on their path to better health," CVS Pharmacy's president, Kevin Hourican, said in a statement.

Patients hoping to use CVS' delivery will need to be patient and pay for the convenience. To have their orders filled and delivered in one or two days, CVS will charge $4.99. For same-day delivery, the company will charge $8.99.

CVS introduced same-day delivery to New York City at the end of last year. It's now expanding it to Boston, Miami, Philadelphia, San Francisco and Washington, D.C.

Customers can place their orders online, through the drugstore's app or over the phone, and can add over-the-counter products like cold and flu medicines, vitamins and baby or feminine care products.

This bundled approach could help CVS counteract declines in traffic as people avoid brick-and-mortar stores and opt to instead buy their goods online, often at less expensive prices. CVS' so-called front-of-store sales, which include everything from shampoo to greeting cards, has been declining.

CVS could even find a sweet spot in over-the-counter medicines. So far, consumers haven't been buying medicines as much online as they have with other household items. People tend to wait until they're sick and need something instead of stocking up in advance.

CVS will ship the products through the U.S. Postal Service, which can leave them at customers' homes even if they're not there.

CNBC has reported that Amazon may enter the prescription drug market. The possibility has weighed on drugstore stocks, including CVS and rivals Walgreens Boots Alliance and Rite Aid. The e-commerce giant already sells private label over-the-counter drugs through a partnership with Perrigo, and has obtained pharmacy licenses in a handful of states. Amazon has licenses to distribute medical devices in nearly all U.S. states.

Amazon has not appeared to crack the code on prescription drugs quite yet. CNBC reported in April the company had shelved a plan to sell drugs directly to hospitals through its Amazon Business unit. Investors in drugstore stocks welcomed the news, easing up on some of the pressure they faced.

Amazon also is partnering with Berkshire Hathaway and J.P. Morgan Chase to form a new health-care venture aimed at lowering the cost of its employee health benefits.

CVS is also undergoing its own evolution. Late last year, it announced a $69 billion deal to merge with health insurer Aetna.