Connect AWS Code Commit repo programmatically from Java/SpringBoot

I have a repo in AWS code Commit which I can clone to my local. Now my requirement is to connect that repository and read and download one file (e.g POM.xml) to my local system without using clone feature.

I have similar functionality in GitHub repo. It works fine using github api url as follows https://api.github.com/repos/{user}/{reponame}/contents?ref={brach_name} and SpringBoot RestTemplate.

But when I try to connect to CodeCommit in the same fashion it does not work rather gives

org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden: [ Invalid request

could any body suggest where I’m making mistake.

I have similar functionality in GitHub repo. It works fine using github api url as follows https://api.github.com/repos/{user}/{reponame}/contents?ref={brach_name} and SpringBoot RestTemplate.

But when I try to connect to CodeCommit in the same fashion it does not work rather gives

org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden: [ Invalid request