question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Publishing npm to AWS CodeArtifact

See original GitHub issue

Hi,

I would like to publish npm packages to AWS CodeArtifact. The special point at this npm registry is the authorization token which is only valid for 12 hours. A new token can be requested using AWS CLI command aws codeartifact login (see documentation).

Would you accept a PR that implements this feature?

Proposed solution: Get a new authorization token for AWS CodeArtifact in the release workflow before publishing the artifact to the npm registry.

I did a first test with this code snipped in release.yml:

- name: Release
  run: |
    export NPM_TOKEN=`aws codeartifact get-authorization-token --domain my_domain --domain-owner 111122223333 --query authorizationToken --output text`
    npx -p jsii-release@latest jsii-release-npm
  env:
    NPM_DIST_TAG: latest
    NPM_REGISTRY: my_domain-111122223333.d.codeartifact.region.amazonaws.com/npm/my_repo/
    AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
    AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}

This command has to be inserted as an additional command in section run if publishing to AWS CodeArtifact is enabled:

export NPM_TOKEN=`aws codeartifact get-authorization-token --domain my_domain --domain-owner 111122223333 --query authorizationToken --output text`.

AWS CLI uses the following environment variables:

  • AWS_ACCESS_KEY_ID -> new configuration in .projenrc.js
  • AWS_SECRET_ACCESS_KEY -> use GitHub secrets (instead of NPM_TOKEN)
  • AWS_DEFAULT_REGION -> new configuration in .projenrc.js

In addition, command aws codeartifact get-authorization-token requires values for domain and domain owner. I would try to extract them from the URL in NPM_REGISTRY.

Trigger for publishing to AWS CodeArtifact: npm registry URL that contains regex .codeartifact.*.amazonaws.com.

I would be happy to have your feedback.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jumiccommented, Oct 17, 2021

Can we open my PR again? I will update it to the current main branch.

1reaction
eladbcommented, Aug 15, 2021

Yes, that will be an awesome addition. I am wondering if perhaps this should be implemented directly in jsii-release, so it’s supported across the board.

Would be nice to automatically deduce that we are targeting CodeArtifact through the NPM_REGISTRY value and then require the AWS_xxx environment variables to be defined.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Publishing private npm packages with AWS CodeArtifact
This post demonstrates how to create, publish, and download private npm packages using AWS CodeArtifact, allowing you to share code across ...
Read more >
Create a Free Private NPM Repository on AWS With ...
AWS Console. In AWS Console go to Developer Tools -> CodeArtifact or search for it, click Create Repository on the right: · Create...
Read more >
Using AWS CodeArtifact to host just your private NPM packages
... shared across a plethora of CI pipelines, I was really excited to see AWS CodeArtifact launch with support for publishing NPM packages....
Read more >
npm publish not working on AWS CodeArtifact - Stack Overflow
The problem was that I was using two different package managers, yarn and npm to do several tasks in this project.
Read more >
Publish private NPM packages securely with scopes on ...
Publish · Create a fresh package using the AWS repository name as an NPM scope. · Go to the CodeArtifact panel. · Click...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found