Is it possible to use AWS CodeArtifact in Netlify builds?

Is it possible to use AWS CodeArtifact in a Netlify build? I’m getting this error:

9:36:31 PM: > diner-guide@0.1.0 preinstall /opt/build/repo
9:36:31 PM: > curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip” && unzip -q awscliv2.zip && ./aws/install && npm run co:login
9:36:31 PM: % Total % Received % Xferd Average Speed Time Time Time Current
9:36:31 PM: Dload Upload Total Spent Left Speed
9:36:31 PM: 0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
9:36:31 PM: 22 41.4M 22 9599k 0 0 24.2M 0 0:00:01 --:–:-- 0:00:01 24.2M
9:36:31 PM: 100 41.4M 100 41.4M 0 0 80.0M 0 --:–:-- --:–:-- --:–:-- 80.0M
9:36:33 PM: mkdir: cannot create directory ‘/usr/local/aws-cli’: Permission denied
9:36:33 PM: npm ERR! code ELIFECYCLE
9:36:33 PM: npm ERR! errno 1
9:36:33 PM: npm ERR! diner-guide@0.1.0 preinstall: curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip -q awscliv2.zip && ./aws/install && npm run co:login
9:36:33 PM: npm ERR! Exit status 1
9:36:33 PM: npm ERR!
9:36:33 PM: npm ERR! Failed at the diner-guide@0.1.0 preinstall script.
9:36:33 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
9:36:33 PM: npm ERR! A complete log of this run can be found in:
9:36:33 PM: npm ERR! /opt/buildhome/.npm/_logs/2021-05-10T12_36_33_937Z-debug.log
9:36:33 PM: Error during NPM install
9:36:33 PM: Build was terminated: Build script returned non-zero exit code: 1
9:36:33 PM: Creating deploy upload records
9:36:34 PM: Failing build: Failed to build site
9:36:34 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 1
9:36:34 PM: Finished processing build request in 13.775252253s

Hi, @gazpachu. I don’t know of any reason that it would be possible to use AWS CodeArtifact during Netlify’s builds. I also don’t know of anyone else doing this before though so I don’t have prior art to explain how to do so. We’d be happy to troubleshoot with you though.

Looking at the error above, it is about directory permissions for /usr/local:

9:36:33 PM: mkdir: cannot create directory ‘/usr/local/aws-cli’: Permission denied

Looking at the AWS CLI documentation, it looks like you can override the install directory with -i to overcome this error:

Installs the AWS CLI v2

USAGE:
    install [FLAGS] [OPTIONS]

FLAGS:
    -u, --update              Updates the AWS CLI v2 if a different version
                              is previously installed. By default, this script
                              will not update the AWS CLI if a previous
                              installation is detected.

    -h, --help                Prints help information

OPTIONS:
    -i, --install-dir <path>  The directory to install the AWS CLI v2. By
                              default, this directory is: /usr/local/aws-cli

    -b, --bin-dir <path>      The directory to store symlinks to executables
                              for the AWS CLI v2. By default, the directory
                              used is: /usr/local/bin

Note, this may mean that your npm run co:login script will need to be modified to point to the new installation directory or that you will need to export the new directory in the PATH environment variable like so:

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
mkdir aws-bin
./aws/install -i ~/aws-bin
export PATH="$HOME/aws-bin:$PATH"
npm run co:login

It might take some changes to get that working but that should be the general solution above.

Hi Luke,

Thanks a lot for your reply. I’ve tried your suggestion but unfortunately it didn’t work:

7:54:22 PM: ln: failed to create symbolic link '/usr/local/bin/aws': Permission denied
7:54:22 PM: ln: failed to create symbolic link '/usr/local/bin/aws_completer': Permission denied

Hi, @gazpachu. It looks like the --bin-dir will also been needed to override the user of /usr/local/bin. Quoting the documentation above:

    -b, --bin-dir <path>      The directory to store symlinks to executables
                              for the AWS CLI v2. By default, the directory
                              used is: /usr/local/bin

As you cannot write to /usr/local/bin, another location must be used.

I give up. Now there are authentication issues that require running aws configure… Thanks for the help!