Search code examples
amazon-web-servicesnpmyarnpkgaws-codeartifact

Automate Codeartifact login for npm


AWS Codeartifact auth token expires after 12hrs, we need to create new token again.

But how can we automate this authentication token update instead of running the command again manually?

I've tried setting the command in ~/.bashrc, but this is running everytime the terminal is opened, need to reduce this command executions.


Solution

  • According to this, the maximum is 43200 seconds (12h). Your question says that you already know how to re-new the token, so no advice needed on this.

    You could:

    • Just run the login command manually
    • Run codefactory login command before the cpm commands by adjusting your build shortcuts (like this question did)
    • Update the bashrc to only run 12h after the last login execution, by remembering when the last login command was executed.

    I personal like the second method the best.