aws-amplify / aws-amplify/amplify-hosting

Command hook for frontend SSG deployments

Open
#3,914 1 comment 0 reactions 0 assignees View on GitHub
feature-request
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have removed any sensitive information from my code snippets and submission.

### Amplify Hosting feature

Build settings, Frontend builds

### Is your feature request related to a problem? Please describe:

I am having a use-case of developing several NextJS applications (SSG) and deploying them to AWS Amplify. I am using AWS amplify hosting, where directly linking each GitHub repository to amplify apps. And configuring YAML file for frontend deployment. All applications are deployed and working fine.

Problem statement: Now I need to setup a quality gate in the deployment process, Where I have to check certain parameters (Package version of few NPM modules) before deployment.

I am trying to implement this with command hooks. Officially its mentioned pre and post push hooks will get triggered by default in amplify hosting.

I have added amplify/hooks folder.

When I tried to trigger a build, these hook scripts are not getting executed. Is it applicable only for backend execution?

Is there any other better way to handle this use-case with AWS amplify CICD for SSG deployments?

### Describe how you'd like this feature to work

Currently I am trying with cURL to pass the data to an API.

version: 1
frontend:
phases:
preBuild:
commands:
- NEXT_VERSION=$(node -p -e "require('./package.json').dependencies.next")
- REACT_VERSION=$(node -p -e "require('./package.json').dependencies.react")
- echo $NEXT_VERSION
- echo $REACT_VERSION
- RES=$(curl -s -X POST -H "Content-type: application/json" -d {"next":"1.00","react":"1.1.0"} [endpoint])
- echo $RES
- npm ci
build:
commands:
- rm -rf .next
- npm run build
artifacts:
baseDirectory: .next/
files:
- '**/*'
cache:
paths:
- node_modules/**/*

But receiving an error as

[ERROR]: !!! CustomerError: The commands provided in the buildspec are malformed. Please ensure that you have properly escaped reserved YAML characters. If you have a ':' character in your command, encapsulate the command within quotes.

But while executing the same buildspec without assigning the curl response to a variable its executing properly.

Is there any easy way to post required info to external APIs via hooks in frontend deployment.

Contributor guide

Open the contributing guide

Research direction

Start with the mentioned amplify/hooks directory and the frontend buildspec, especially the preBuild phase, then compare the curl command when its response is assigned to RES with the version that runs without the assignment. Confirm whether frontend SSG builds execute these hooks and what completed behavior should support posting version data to an external API.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, next.js
Domain
ci-cd, cloud, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.