- Newest
- Most votes
- Most comments
The issue you're experiencing with AWS Amplify triggering builds for your monorepo on every commit, even when there are no changes in the frontend folder, is likely due to how Amplify handles monorepo configurations by default.
While you've correctly set up the monorepo settings with the appRoot and AMPLIFY_MONOREPO_APP_ROOT pointing to the frontend folder, Amplify's default behavior is to trigger builds for all commits to the connected branch, regardless of which files have changed.
To address this issue and make Amplify more selective about when it triggers builds for your monorepo, you can implement a custom build trigger using AWS CodeBuild in combination with Amazon EventBridge (formerly CloudWatch Events). This approach allows you to create a more granular rule that only initiates builds when changes occur in the frontend directory.
Here's a high-level overview of how you can set this up:
- Create an Amazon EventBridge rule that listens for CodeCommit repository state changes.
- Set up a Lambda function that checks which files have changed in the commit.
- If changes are detected in the frontend folder, the Lambda function can trigger the Amplify build using the AWS SDK.
This custom solution gives you more control over when builds are triggered, ensuring that Amplify only rebuilds and redeploys your Next.js app when there are actual changes in the frontend directory.
It's worth noting that while Amplify's CI/CD works well with monorepos, including support for tools like Nx and Yarn Workspaces, the default behavior is to build on every commit. The custom approach described above allows you to fine-tune this behavior to better suit your specific monorepo structure and build requirements.
Remember to implement appropriate security measures and follow AWS best practices when setting up this custom build trigger solution.
Sources
Introducing the Next Generation of AWS Amplify’s Fullstack Development Experience | Front-End Web & Mobile
Trigger AWS CodeBuild builds automatically - AWS CodeBuild
answered 2 years ago
Relevant content
asked 2 years ago
