0

I have a private npm package that I have published to AWS CodeArtifact so I can use it across a ReactJS App and NodeJS/Express API app.

Version 1.0.0 of this package is published to CodeArtifact.

In my ReactJS App, I have a dependency in package.json as "@name-space/name-of-package": "^1.0.0"

I’ve changed the registry for @name-space to point to the CodeArtifact URL. For all other packages I’m still using the default NPM registry (https://registry.npmjs.com). I have this configured via an .npmrc file in my ReactJs project.

When I try to deploy my ReactJS app via AWS Amplify I get an error in the build: ERR! Invalid Version: ^1.0.0

I’m new to virtually everything I’m working with here - creating private packages, CodeArtifact, and Amplify, so I’m not sure if I’m missing any steps.

I've tried removing the "^" from the version in the ReactJS package.json, but then I get ERR! Invalid Version: 1.0.0 when trying to build.

Any idea how I can get rid of this error and get a successful build of my ReactJS app deployed via Amplify?

havab
  • 33
  • 1
  • 5

1 Answers1

1

You will also need to update your amplify.ymlto login to CodeArtifact. Here is an example...

frontend:
  phases:
    preBuild:
      commands:
        - pip3 install awscli --upgrade --user
        - aws codeartifact login --tool npm --repository repository_name --domain domain_name --domain-owner domain_owner_id
        - npm ci
Alex
  • 952
  • 7
  • 12
  • thanks @Alex. I get a warning about the pip3 command: "Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead." I'm assuming I need to provide a username after --user...would that be an IAM user that has access to the package in CodeArtifact? I'm also getting an error, but I figured I'd get clarity on this question first. Thanks for the help! – havab May 13 '21 at 20:16
  • I think it's ok to ignore this warning and drop the --user flag. This install is happening on an ephemerial build container. I've been running Amplify builds like this for over a year with success. Share your other error and I can help out there as well. – Alex May 13 '21 at 20:43
  • Ok great, thanks @Alex. Here is the error [INFO]: # Executing command: aws codeartifact login --tool npm --repository repo-name --domain domain-name --domain-owner 000 [WARNING]: An error occurred (AccessDeniedException) when calling the GetAuthorizationToken operation: User: arn:aws:sts::000:assumed-role/AemiliaControlPlaneLambda-CodeBuildRole-1PJH7JZRIQRPI/AWSCodeBuild-[GUID] is not authorized to perform: codeartifact:GetAuthorizationToken on resource: arn:aws:codeartifact:us-east-1:0123456789:domain/domain-name [ERROR]: !!! Build failed [ERROR]: !!! Non-Zero Exit Code detected – havab May 13 '21 at 20:50
  • I had to remove some of the identifiers in my comment above to make the error fit – havab May 13 '21 at 20:51
  • I notice that repo-name and domain-name are still filled in. You will need to drop in your CodeArtifact specific values there. You should be able to find them in the AWS Console. – Alex May 13 '21 at 20:58
  • Sorry @Alex I should have mentioned that I pulled out my actual domain and repo names and replaced them with generic values. In my actual amplify.yaml the correct values are there – havab May 13 '21 at 21:16
  • Double check that your amplifyconsole-backend-role IAM role has permissions to codeartifact:GetAuthorizationToken and sts:GetServiceBearerToken https://docs.aws.amazon.com/codeartifact/latest/ug/auth-and-access-control-permissions-reference.html – Alex May 13 '21 at 21:46