The officer joined his superior, Colonel Henry Leavenworth, in an engagement against the Arikara Indians in August 1823. Riley was honored for ten years of faithful service by being promoted to Brevet Major on August 6, 1828. Eventually he gained the rank of Brevet Colonel in February 1844. Beforehand, he had tenures as Major in the 4th U.S. Infantry (1837) and Lieutenant Colonel, 2nd U.S. Infantry, beginning in December 1839. The Battle of Chokachotta in Florida took place on June 2, 1840. Colonel Riley was cited for bravery and good conduct during this engagement in the Seminole Wars.
During the Mexican-American War, Riley was colonel of the 2nd U.S. Infantry and fought at the siege of Veracruz and battle of Cerro Gordo. He was brevetted brigadier general and assumed command of the 2nd Brigade in David E. Twiggs's Second Division. He led his brigade at the battles of Contreras and Churubusco, where Winfield Scott gave him credit for the U.S. victory. He was appointed brevet major general and fought at the Chapultepec. He is generally considered one of the ablest brigade commanders in the army during the war with Mexico.
In the years 1849 and 1850, General Riley commanded the Military Department in Upper California and exercised the duties of Provincial Governor. After his administrative service concluded on the Pacific, Riley was ordered to take command of a regiment on the Rio Grande. However ill-health prevented further service on his part. He returned to his home in Buffalo, New York.
The many military campaigns he took part in over the years had a deleterious effect on his health. He finally succumbed to an aggravated form of cancer. General Riley died on Thursday evening, June 10, 1853. He left a widow and five children.
Fort Riley and Riley County, Kansas are both named in his honour.