We use CodeArtifact as our npm registry for both Python and javascript code. I am able to pass the CodeArtifact token in the sam build
command using the PIP_INDEX_URL
environment variable. However, I have not been able to figure out how to do the same for npm.
How can I pass the appropriate environment variables to allow npm to access CodeArtifact inside a sam build
container?
The command:
sam build --use-container --container-env-var PIP_INDEX_URL="https://aws:$CODEARTIFACT_AUTH_TOKEN@yyy.d.codeartifact.us-east-1.amazonaws.com/pypi/yyy/simple/" --container-env-var npm_config_registry="https://yyy.d.codeartifact.us-east-1.amazonaws.com/npm/yyy/" --container-env-var npm_config_="//yyy.d.codeartifact.us-east-1.amazonaws.com/npm/yyy/:_authToken=$CODEARTIFACT_AUTH_TOKEN"
The error:
Build Failed
Running NodejsNpmEsbuildBuilder:CopySource
Running NodejsNpmEsbuildBuilder:NpmCI
Error: NodejsNpmEsbuildBuilder:NpmCI - NPM Failed: npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR! npm login
I feel like the problem may be trying to replicate the 2nd line in this .npmrc content in env vars:
registry=https://my_domain-111122223333.d.codeartifact.us-west-2.amazonaws.com/npm/my-cli-repo/
//my_domain-111122223333.d.codeartifact.us-west-2.amazonaws.com/npm/my_repo/:_authToken=eyJ2ZX...
Reference for npm for CodeArtifact: https://docs.aws.amazon.com/codeartifact/latest/ug/npm-auth.html