The gunman who set an ambush last summer for police in Baton Rouge, La., had written about killing officers before the attack, according to a new report released Friday by the local prosecutor.

Three lawmen were killed and three others were wounded on July 17, 2016, near a convenience store close to police headquarters. It happened less than two weeks after Baton Rouge had erupted in protests after the fatal shooting of Alton Sterling, a black man killed in a struggle with police. The events had Baton Rouge on edge, with emotions raw.

The report includes video and still images of the shooter, 29-year-old Gavin Long, an Iraqi war veteran from Missouri. He's dressed in all black with a hood and face mask, armed with a rifle over his shoulder. The video shows him shooting officers in a 13-minute ordeal that ended when Long was killed in a gunfight with a special response team.

The fallen officers were Sheriff's Deputy Brad Garafola, and Baton Rouge policemen Montrell Jackson and Matthew Lane Gerald.

The nearly year-long investigation by local, state and federal officials concludes that Long was killed "in the course and scope of their employment as law enforcement officers and under circumstances where their use of deadly force was legally justified."

East Baton Rouge Parish District Attorney Hillar Moore III says Long left a three-page suicide note in his rental car in which he talked about the "destruction" he must inflict upon cops.

"He had angst and animus against police officers whether good or bad," says Moore, describing the letter. "He says he understands he may have to kill even good officers – that good officers may have to die because [of] bad officers."

Investigators say Long had searched online for the home addresses of Baton Rouge policemen involved in the fatal shooting of Sterling. He had posted online video calling for bloodshed in response to police-involved killings before coming to Baton Rouge on July 12.

Copyright 2017 NPR. To see more, visit http://www.npr.org/.