Hooks in Amplify v.10.0.0 runs only once(first time when branch is connected) in CI/CD Pipeline. Locally - as expected.
See original GitHub issueBefore opening, please confirm:
- I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- I have searched for duplicate or closed issues.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- I have removed any sensitive information from my code snippets and submission.
How did you install the Amplify CLI?
remote config
If applicable, what version of Node.js are you using?
16.15.9
Amplify CLI Version
10.0.0
What operating system are you using?
Linux
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
Depends
Amplify Categories
hosting
Amplify Commands
push
Describe the bug
Starting with Amplify v.10.0.0, the hooks should be checked in to the source control. I have a post-push.js hook which is needed to be triggered. After connecting the branch in the CI/CD Pipeline in the Amplify Console for the first time, the hook is executed with success. If another commit/build is triggered, the build runs without executing the hook.
Locally, every time the amplify push
is executed, the hook is also triggered.
Expected behavior
The hook is triggered at every CI/CD build trigger.
Reproduction steps
- Have a post-push.js in the amplify/hooks folder.
- Connect a branch in CI/CD.
- Wait for the first build.
- Check if hook is executed(is should).
- Push some change with a new commit to the branch.
- Wait for the second build.
- Check if the hook is executed.
GraphQL schema(s)
# Put schemas below this line
//NOT_RELEVANT
Project Identifier
a88954c5b3c47e78dce85b3e0fd819c8
Log output
First build
2022-09-17T14:10:58.046Z [INFO]: [0mGraphQL transformer version: 2[0m
2022-09-17T14:10:58.072Z [INFO]:
2022-09-17T14:10:58.132Z [INFO]: ✅ Initialized your environment successfully.
2022-09-17T14:10:58.132Z [INFO]: [32mYour project has been successfully initialized and connected to the cloud![39m
[32mSome next steps:[39m
[0m"amplify status" will show you what you've added already and if it's locally configured or deployed[0m
[0m"amplify add <category>" will allow you to add features like user login or a backend API[0m
[0m"amplify push" will build all your local backend resources and provision it in the cloud[0m
[0m"amplify console" to open the Amplify Console and view your project status[0m
[0m"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud[0m
[32mPro tip:[39m
[0mTry "amplify add api" to create a backend API and then "amplify push" to deploy everything[0m
2022-09-17T14:10:58.144Z [INFO]:
2022-09-17T14:10:58.144Z [INFO]: ----- 🪝 post-push execution start -----
2022-09-17T14:10:58.939Z [INFO]: Running post push hooks scripts...
2022-09-17T14:10:59.055Z [INFO]: Setting cognito triggers...
2022-09-17T14:11:01.382Z [INFO]: Finished configuring triggers
Second Build
2022-09-17T14:36:59.793Z [INFO]: [0mGraphQL transformer version: 2[0m
2022-09-17T14:36:59.808Z [INFO]:
2022-09-17T14:36:59.865Z [INFO]: ✅ Initialized your environment successfully.
2022-09-17T14:36:59.865Z [INFO]: [32mYour project has been successfully initialized and connected to the cloud![39m
[32mSome next steps:[39m
[0m"amplify status" will show you what you've added already and if it's locally configured or deployed[0m
[0m"amplify add <category>" will allow you to add features like user login or a backend API[0m
[0m"amplify push" will build all your local backend resources and provision it in the cloud[0m
[0m"amplify console" to open the Amplify Console and view your project status[0m
[0m"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud[0m
[32mPro tip:[39m
[0mTry "amplify add api" to create a backend API and then "amplify push" to deploy everything[0m
⚠️ The maximum number of apps that you can create with Amplify in this region has likely been reached:
For more information on Amplify Service Quotas, see:
https://docs.aws.amazon.com/general/latest/gr/amplify.html#service-quotas-amplify
2022-09-17T14:37:02.291Z [INFO]: # Completed phase: build
Additional information
No workaround yet.
But, if you check the second build logs, there is that error: “The maximum number of apps that you can create with Amplify in this region has likely been reached” related to https://github.com/aws-amplify/amplify-hosting/issues/2797 Could be that it breaks the execution of the hooks.
Worth to mention that the script: https://github.com/aws-amplify/amplify-hosting/blob/main/scripts/amplifyPush.sh is used for remote deployment. Maybe it should be updated also.
Update:
The issue is definitely in the https://github.com/aws-amplify/amplify-hosting/blob/main/scripts/amplifyPush.sh.
I did run the deployment without --simple flag, and at least it executes the hooks:
Update:
Dropping the --simple
flag and have a branch name without special characters (see: https://github.com/aws-amplify/amplify-cli/issues/979), then the hooks are executed as expected, at each build, but it fails because it tries to re-create the stack.

Conclusion:
After the first build, the stack is pulled from the cache, and it doesn’t have the hooks because they are not stack related.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:17 (9 by maintainers)
Just followed up with Hosting. This is in fact the expected behavior.
AMPLIFY_DIFF_BACKEND checks to see if there are any code changes - If there’s no change since the previous commit, the build is skipped
Unfortunately, I have to re-open it. After more testing, the hooks are still running only once - at the first build.
More findings.
How to reproduce the issue: 1 build:
2 build: