Skip to content

Commit a52a435

Browse files
docs(nx-cloud): add install-aws-cli launch template step usage info (#31255)
## Current Behavior aws cli usage in Nx Agents is undocumented ## Expected Behavior aws cli step is documented for Nx Agents preview: https://nx-dev-git-docs-add-aws-cli-workflow-step-nrwl.vercel.app/ci/reference/launch-templates#aws-cli-on-nx-agents --------- Co-authored-by: Nicole Oliver <[email protected]>
1 parent 9228e9f commit a52a435

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

docs/nx-cloud/reference/launch-templates.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ To do this, run the `nx-cloud validate` command, with the path to the launch tem
418418
nx-cloud validate --workflow-file=./.nx/workflows/agents.yaml
419419
```
420420

421-
## Pass Environment Variables to Agents
421+
## Pass Environment Variables
422422

423423
If you need to send environment variables to agents, you can use the [--with-env-vars](/ci/reference/nx-cloud-cli#withenvvars-nx-agents-only) flag on the `nx-cloud start-ci-run` command. You can pass a specific list of environment variables like this:
424424

@@ -555,7 +555,7 @@ Nx Agents have [corepack enabled](https://nodejs.org/api/corepack.html#corepack)
555555
Currently, corepack [only supports yarn or pnpm](https://nodejs.org/api/corepack.html#supported-package-managers) as package managers. If you need to use a specific npm version, you will need to create a custom launch template and install the specific npm version, i.e. `npm install -g npm@<version>`
556556
{%/callout %}
557557

558-
## Installing Packages on Nx Agents
558+
## Installing Packages
559559

560560
You can use `apt` to install popular linux packages. This is helpful in streamlining setting up various toolchains needed for your workspace.
561561

@@ -576,6 +576,66 @@ launch-templates:
576576
If you're trying to install a package that isn't available on `apt`, check that packages install steps for Debian base linux. Usually there are a handful of installation scripts that can be used [similar to `nvm`](#custom-node-version)
577577
{% /callout %}
578578

579+
## AWS CLI
580+
581+
First, define the environment variables on your main agent, where you call [`nx-cloud start-ci-run`](/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun). Pass the same environment variables to your agents via the [`--with-env-vars` flag](/ci/reference/nx-cloud-cli#withenvvars-nx-agents-only).
582+
583+
Minimally the `AWS_REGION` (or `AWS_DEFAULT_REGION`), `AWS_ACCESS_KEY_ID`, and `AWS_SECRET_ACCESS_KEY` environment variables are required.
584+
585+
{% callout type="check" title="OIDC Provider" %}
586+
If using an [OIDC provider](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html), e.g. the [AWS GitHub Action recommended setup](https://github.com/aws-actions/configure-aws-credentials?tab=readme-ov-file#using-this-action), then the environment variables are automatically configured for you after authentication to AWS. Since the credentials created for with OIDC provider flow are temporary, you'll need to pass the `AWS_SESSION_TOKEN` environment variable to your agents.
587+
588+
{% /callout %}
589+
590+
{% tabs %}
591+
{% tab label="Pre-Built Step" %}
592+
593+
Using the pre-built step simplifies and provides debugging checks to make sure the AWS CLI is properly authenticated to AWS before continuing. The step is recommended for most use cases.
594+
595+
```yaml {% fileName="./nx/workflows/agents.yaml" highlightLines=["6-8"]%}
596+
launch-templates:
597+
my-linux-medium-js:
598+
resource-class: 'docker_linux_amd64/medium'
599+
image: 'ubuntu22.04-node20.11-v9'
600+
init-steps:
601+
- name: Install AWS CLI
602+
uses: 'nrwl/nx-cloud-workflows/v5/workflow-steps/install-aws-cli/main.yaml'
603+
# no additional inputs required, as all configuration is via environment variables via --with-env-vars
604+
```
605+
606+
{% /tab %}
607+
{% tab label="Manual Installation" %}
608+
609+
Manual installation follows [installing the AWS CLI using the official directions](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html). In order to decompress the installation archive, you'll need to install the `unzip` package in your step.
610+
Manual installation is helpful if a custom installation setup is required.
611+
It is helpful to run `aws sts get-caller-identity` command to make sure you're properly authenticated to AWS before proceeding
612+
613+
```yaml {% fileName="./nx/workflows/agents.yaml" highlightLines=["6-20"] %}
614+
launch-templates:
615+
my-linux-medium-js:
616+
resource-class: 'docker_linux_amd64/medium'
617+
image: 'ubuntu22.04-node20.11-v9'
618+
init-steps:
619+
# step assumes you've passed all required AWS_* environment variables from the main agent via --with-env-vars
620+
- name: Install AWS CLI
621+
script: |
622+
# unzip is required to unzip the AWS CLI installer
623+
sudo apt install gh unzip -y
624+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
625+
unzip awscliv2.zip
626+
# run installer, default location is already in the PATH
627+
# if installing in a custom location,
628+
# then update the $PATH like `PATH=$PATH:[extra-path-items] >> $NX_CLOUD_ENV`
629+
sudo ./aws/install
630+
# print AWS CLI version to verify command is avaiable
631+
aws --version
632+
# verify credentials to AWS is working
633+
aws sts get-caller-identity
634+
```
635+
636+
{% /tab %}
637+
{% /tabs %}
638+
579639
## Dynamic Changesets
580640

581641
NxCloud can calculate how big your pull request is based on how many projects in your workspace it affects. You can then configure Nx Agents to dynamically use a different number of agents based on your changeset size.

0 commit comments

Comments
 (0)