Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit 378a2ea

Browse files
committed
Add "Using CodeArtifact with npm"
1 parent 5a26c7c commit 378a2ea

File tree

1 file changed

+79
-3
lines changed
  • content/en/user-guide/aws/codeartifact

1 file changed

+79
-3
lines changed

content/en/user-guide/aws/codeartifact/index.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,86 @@ The following output is displayed:
260260
Please note, a repository can have one or more upstream repositories, or an external connection.
261261
{{< /callout >}}
262262

263+
## Using CodeArtifact with npm
264+
265+
### Configuring npm with the login command
266+
267+
Use the `awslocal codeartifact login` command to fetch credentials for use with npm.
268+
269+
{{< command >}}
270+
$ awslocal codeartifact login --tool npm --domain demo-domain --repository demo-repo
271+
{{< /command >}}
272+
273+
This command makes the following changes to your `~/.npmrc` file:
274+
275+
- Adds an authorization token after fetching it from CodeArtifact using your AWS credentials.
276+
- Sets the npm registry to the repository specified by the `--repository` option.
277+
- **For npm 6 and lower:** Adds `"always-auth=true"` so the authorization token is sent for every npm command.
278+
279+
The default authorization period after calling login is 12 hours, and login must be called to periodically refresh the token.
280+
For more information about the authorization token created with the login command, see [Tokens created with the login command](https://docs.aws.amazon.com/codeartifact/latest/ug/tokens-authentication.html#auth-token-login).
281+
282+
### Configuring npm manually
283+
284+
You can configure npm with your CodeArtifact repository without the `awslocal codeartifact login` command by manually updating the npm configuration.
285+
286+
#### To configure npm without using the login command
287+
288+
1. In a command line, fetch a CodeArtifact authorization token and store it in an environment variable.
289+
npm will use this token to authenticate with your CodeArtifact repository.
290+
291+
{{< command >}}
292+
$ export CODEARTIFACT_AUTH_TOKEN=$(awslocal codeartifact get-authorization-token --domain demo-domain --query authorizationToken --output text)
293+
{{< /command >}}
294+
295+
2. Get your CodeArtifact repository's endpoint by running the following command.
296+
Your repository endpoint is used to point npm to your repository to install or publish packages.
297+
298+
{{< command >}}
299+
$ awslocal codeartifact get-repository-endpoint --domain demo-domain --repository demo-repo --format npm
300+
{{< /command >}}
301+
302+
The following URL is an example repository endpoint.
303+
304+
```text
305+
http://demo-domain-000000000000.d.codeartifact.eu-central-1.localhost.localstack.cloud/npm/demo-repo/
306+
```
307+
308+
3. Use the `npm config set` command to set the registry to your CodeArtifact repository.
309+
Replace the URL with the repository endpoint URL from the previous step.
310+
311+
{{< command >}}
312+
$ npm config set registry http://demo-domain-000000000000.d.codeartifact.eu-central-1.localhost.localstack.cloud/npm/demo-repo/
313+
{{< /command >}}
314+
315+
4. Use the `npm config set` command to add your authorization token to your npm configuration.
316+
317+
{{< command >}}
318+
$ npm config set //demo-domain-000000000000.d.codeartifact.eu-central-1.localhost.localstack.cloud/:_authToken=${CODEARTIFACT_AUTH_TOKEN}
319+
{{< /command >}}
320+
321+
**For npm 6 or lower:** To make npm always pass the auth token to CodeArtifact, even for GET requests, set the always-auth configuration variable with npm config set.
322+
323+
{{< command >}}
324+
$ npm config set //demo-domain-000000000000.d.codeartifact.eu-central-1.localhost.localstack.cloud/:always-auth=true
325+
{{< /command >}}
326+
327+
#### Example npm configuration file (`.npmrc`)
328+
329+
The following is an example `.npmrc` file after following the preceding instructions to set the CodeArtifact registry endpoint, add an authentication token, and configure `always-auth`.
330+
331+
```text
332+
registry=http://demo-domain-000000000000.d.codeartifact.eu-central-1.localhost.localstack.cloud/npm/demo-repo/
333+
//demo-domain-000000000000.d.codeartifact.eu-central-1.localhost.localstack.cloud/:_authToken=eyJ2ZX...
334+
//demo-domain-000000000000.d.codeartifact.eu-central-1.localhost.localstack.cloud/:always-auth=true
335+
```
336+
263337
## Current Limitations
264338

265339
LocalStack doesn't support the following features yet:
266340

267-
- Domain and repository permission policies
268-
- Packages and package groups handlers
269-
- Retrieving repository endpoints
341+
- Domain owners are ignored
342+
- Copying package versions is not supported yet
343+
- Domain and repository permission policies are not supported yet
344+
- Package groups are not supported yet
345+
- Only supports the `npm` format

0 commit comments

Comments
 (0)