question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Before 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

  1. Have a post-push.js in the amplify/hooks folder.
  2. Connect a branch in CI/CD.
  3. Wait for the first build.
  4. Check if hook is executed(is should).
  5. Push some change with a new commit to the branch.
  6. Wait for the second build.
  7. 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]: GraphQL transformer version: 2
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]: Your project has been successfully initialized and connected to the cloud!
                                 Some next steps:
                                 "amplify status" will show you what you've added already and if it's locally configured or deployed
                                 "amplify add <category>" will allow you to add features like user login or a backend API
                                 "amplify push" will build all your local backend resources and provision it in the cloud
                                 "amplify console" to open the Amplify Console and view your project status
                                 "amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud
                                 Pro tip:
                                 Try "amplify add api" to create a backend API and then "amplify push" to deploy everything
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]: GraphQL transformer version: 2
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]: Your project has been successfully initialized and connected to the cloud!
                                 Some next steps:
                                 "amplify status" will show you what you've added already and if it's locally configured or deployed
                                 "amplify add <category>" will allow you to add features like user login or a backend API
                                 "amplify push" will build all your local backend resources and provision it in the cloud
                                 "amplify console" to open the Amplify Console and view your project status
                                 "amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud
                                 Pro tip:
                                 Try "amplify add api" to create a backend API and then "amplify push" to deploy everything
                                 ⚠️ 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: Screenshot 2022-09-17 at 21 37 59

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.

Screenshot 2022-09-18 at 01 25 58

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:closed
  • Created a year ago
  • Reactions:1
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
evcodescommented, Nov 18, 2022

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

1reaction
hackmajoriscommented, Oct 28, 2022

Unfortunately, I have to re-open it. After more testing, the hooks are still running only once - at the first build. image

More findings.

How to reproduce the issue: 1 build:

  amplify.yml
    backend:
            build:
              commands:
                - ls amplify/hooks # it will show the files from git             
                - amplifyPush --simple # it will generate a new env at the first build. The amplify/hooks folder will not be replaced.          
                - ls amplify/hooks # the files are there

2 build:

  amplify.yml
    backend:
            build:
              commands:
                - ls amplify/hooks # it will show the files from git             
                - amplifyPush --simple # it will pull the existing env. The amplify/hooks folder WILL be replaced. Because they are not present on S3, the folder will be empty.         
                - ls amplify/hooks # the files are not there, the hooks are not executed.
Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-sdk | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Program Repair
In this paper, we present a comprehensive survey of the state of the art in program repair. We first study the different suite...
Read more >
Index of bucket main - Scoop Apps
ect 0.9.3 Fast and effective C++ file optimizer. jabba 0.11.2 Java Version Manager neovim 0.8.1 Vim‑fork focused on extensibility and usability neo‑cowsay 2.0.4 Cowsay written in...
Read more >
ace book surf
... make | about | know | will | up | one | time | there | year | so | think ......
Read more >
Untitled
E8730w, Tanzanite jewellery australia, Un chat qui perd ses moustaches, Door to balloon time exclusions, Ikf blogspot, Just dance good songs, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found