Amazon will donate $8 million to fight homelessness in its two headquarter cities, Seattle and Arlington, Virginia.

The initial donation will include $5 million to Plymouth Housing in Seattle and $3 million to the Arlington Community Foundation, the company said Tuesday. Amazon will also match employee donations to some charities that address housing and homelessness in either location through Sept. 30. Amazon said it will match up to $5 million in employee donations.

Amazon had opposed an effort from the local government last year to tax big businesses to help curb homelessness. The Seattle City Council eventually voted to repeal the tax hike, according the The Washington Post, which would have raised $48 million annually to fund the city's efforts to combat homelessness and provide affordable housing.

Such stances has brought Amazon criticism from local residents and politicians, who say Seattle-based e-commerce giant has not paid its fair share. That sentiment fueled local resistance during Amazon's search for its new headquarters. Amazon faced intense opposition once it selected the dual locations of its second headquarters in Arlington and New York's Long Island City. The push back in New York was so fierce that Amazon ultimately pulled out of that location.

Amazon said it has already made significant contributions toward fighting homelessness in Seattle. The company said in Tuesday's announcement that it has donated over $130 million to local nonprofits Mary's Place and FareStart since 2016, including annual rent.

Amazon said its new donation to Plymouth Housing in Seattle will help support the organization's efforts, including providing permanent homes and services for people with physical disabilities, mental illnesses or chemical dependency. In Virginia, the Arlington Community Foundation helps local nonprofits through grants and special initiatives, according to the press release, focusing on homelessness prevention, education, arts, youth and families in need.

Subscribe to CNBC on YouTube.

Watch: Amazon's new robots to be deployed in warehouses around the country