To explore how microbial community composition and function varies within a coral reef ecosystem, we performed metagenomic sequencing of seawater from four niches across Heron Island Reef, within the Great Barrier Reef. Metagenomes were sequenced from seawater samples associated with (1) the surface of the coral species Acropora palifera, (2) the surface of the coral species Acropora aspera, (3) the sandy substrate within the reef lagoon and (4) open water, outside of the reef crest. Microbial composition and metabolic function differed substantially between the four niches. The taxonomic profile showed a clear shift from an oligot roph-dominated community (e.g. SAR11, Prochlorococcus, Synechococcus) in the open water and sandy substrate niches, to a community characterised by an increased frequency of copiotrophic bacteria (e.g. Vibrio, Pseudoalteromonas, Alteromonas) in the coral seawater niches. The metabolic potential of the four microbial assemblages also displayed significant differences, with the open water and sandy substrate niches dominated by genes associated with core house-keeping processes such as amino acid, carbohydrate and protein metabolism as well as DNA and RNA synthesis and metabolism. In contrast, the coral surface seawater metagenomes had an enhanced frequency of genes associated with dynamic processes including motility and chemotaxis, regulation and cell signalling. These findings demonstrate that the composition and function of microbial communities are highly variable between niches within coral reef ecosystems and that coral reefs host heterogeneous microbial communities that are likely shaped by habitat structure, presence of animal hosts and local biogeochemical conditions.