How to deploy affected NX projects to AWS S3 using Github Actions

First of all, if you don’t know what Nx Workspaces is, I recommend checking it out and learning more! It’s a great tool, especially for monorepos.

In this section of the tutorial, we have an example of how to deploy an application to Netlify.

In this…


This content originally appeared on DEV Community and was authored by Lucas Melo

First of all, if you don’t know what Nx Workspaces is, I recommend checking it out and learning more! It’s a great tool, especially for monorepos.

In this section of the tutorial, we have an example of how to deploy an application to Netlify.

In this tutorial, I’ve brought details on how to deploy to AWS S3 using GitHub Actions.

1. Create a bucket on S3 with all the necessary configurations for a public page.
2. Set up a role for your application to have permission to modify the bucket’s content.
3. Continue setting up your ci.yml file. I used the following configuration:

Remember to update your AWS credentials

name: CI

on:
  push:
    branches: [main]

permissions:
  id-token: write
  actions: read
  contents: read

jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      # Cache node_modules
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'
      - run: npm ci --legacy-peer-deps
      - uses: nrwl/nx-set-shas@v4

      - run: npx nx affected -t test build build-storybook

      - name: Install AWS CLI
        uses: unfor19/install-aws-cli-action@v1
        with:
          version: 1

      - name: Configure aws credentials
        uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: <ROLE>
          role-session-name: <ROLE_NAME>
          aws-region: <AWS_REGION>

      - uses: nrwl/nx-set-shas@v4
      - run: npx nx affected -t deploy

With this configured, all affected applications that have the deploy command will be running. Now, let’s create the deploy command for the applications.

Go to your application's project.json and add the new command.
You need to locate the folder where the build is generated (in my case, dist/apps/) and the bucket where the upload will be done.

"targets": {
    "deploy": {
      "executor": "nx:run-commands",
      "options": {
        "command": "aws s3 sync dist/apps/<YOUR APP> s3://<BUCKET_NAME>/ --delete"
      }
    }
  }

With this, the deployment of affected applications should work perfectly. This tutorial could have saved me a few hours of research looking for a way to do this.

Thank you for reading ;)


This content originally appeared on DEV Community and was authored by Lucas Melo


Print Share Comment Cite Upload Translate Updates
APA

Lucas Melo | Sciencx (2024-10-21T18:53:31+00:00) How to deploy affected NX projects to AWS S3 using Github Actions. Retrieved from https://www.scien.cx/2024/10/21/how-to-deploy-affected-nx-projects-to-aws-s3-using-github-actions/

MLA
" » How to deploy affected NX projects to AWS S3 using Github Actions." Lucas Melo | Sciencx - Monday October 21, 2024, https://www.scien.cx/2024/10/21/how-to-deploy-affected-nx-projects-to-aws-s3-using-github-actions/
HARVARD
Lucas Melo | Sciencx Monday October 21, 2024 » How to deploy affected NX projects to AWS S3 using Github Actions., viewed ,<https://www.scien.cx/2024/10/21/how-to-deploy-affected-nx-projects-to-aws-s3-using-github-actions/>
VANCOUVER
Lucas Melo | Sciencx - » How to deploy affected NX projects to AWS S3 using Github Actions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/10/21/how-to-deploy-affected-nx-projects-to-aws-s3-using-github-actions/
CHICAGO
" » How to deploy affected NX projects to AWS S3 using Github Actions." Lucas Melo | Sciencx - Accessed . https://www.scien.cx/2024/10/21/how-to-deploy-affected-nx-projects-to-aws-s3-using-github-actions/
IEEE
" » How to deploy affected NX projects to AWS S3 using Github Actions." Lucas Melo | Sciencx [Online]. Available: https://www.scien.cx/2024/10/21/how-to-deploy-affected-nx-projects-to-aws-s3-using-github-actions/. [Accessed: ]
rf:citation
» How to deploy affected NX projects to AWS S3 using Github Actions | Lucas Melo | Sciencx | https://www.scien.cx/2024/10/21/how-to-deploy-affected-nx-projects-to-aws-s3-using-github-actions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.