Search code examples
gitamazon-web-servicesnpmsingle-sign-onaws-codecommit

AWS SSO, Codecommit (GRC git clone link) and npm install


Single Sign On (SSO) is implemented on AWS account. After running aws sso login, cloning a node a repo using (GRC link) works. However, running npm install in repo results in different errors.

ex. package.json

...
"dependencies": {
    ...
    "common-resource-1": "git+https://git-codecommit.us-east-1.amazonaws.com/v1/repos/common-resource-1#develop",
   ...
}
...

The errors

npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t https://git-codecommit.us-east-1.amazonaws.com/v1/repos/common-resource-1
npm ERR!
npm ERR! [email protected] : Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128

That makes sense because there are no ssh or https creds. git-remote-codecommit python package is installed as recommended buy AWS https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-git-remote-codecommit.html

However, the following returns repo information: /usr/local/bin/git ls-remote -h -t codecommit://common-resource-1

also tried with putting the following in package.json "common-resource-2": "codecommit::east-1://common-resource-2#develop", The error I get is

npm ERR! code EUNSUPPORTEDPROTOCOL
npm ERR! Unsupported URL Type "codecommit:": codecommit::east-1://common-resource-2#develop

This is an issue for many repos, since other repos use common-resource-1 and common-resource-2 repos.

Any help with this would be greatly appreciated.


Solution

  • If on a mac:

    1. Remove any keychains entries that may pertain to the domain and/or repository in question. This was my main problem.
    2. Use the git credential-helper with aws command as followings:
      [credential "https://git-codecommit.us-east-1.amazonaws.com"]
           UseHttpPath = true
           helper = !aws codecommit credential-helper $@
      

    Note: if on mac and it still does not work, may have to add dummy value for the username attribute.

    [credential "https://git-codecommit.us-east-1.amazonaws.com"]
         UseHttpPath = true
         helper = !aws codecommit credential-helper $@
         username = "dummy"