amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

AMPLIFY_DIFF_BACKEND does not work

Open Voyager-Two opened this issue 3 years ago • 3 comments

Before opening, please confirm:

App Id

No response

Region

us-east-1

Amplify Hosting feature

Backend builds

Describe the bug

Docs: https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html#enable-diff-backend

Backend builds even with:

  • AMPLIFY_DIFF_BACKEND set to true.
  • No code changes to amplify directory.
  • With no custom backend commands in amplify.yml (apart from amplifyPush --simple)

This often adds 4 min unnecessary overhead to builds.

image

In this comment it is stated we can use amplifyPush --simple command, and it should still work.

But it does not: image

image


Docs states the following:

If you currently have custom commands specified in the build settings of your backend phase, conditional backend builds won't work.

However, we require aws-exports as it's deployed to a different environment. So we need to use amplifyPush --simple.

Expected behavior

Skip backend builds if no changes to amplify dir, without having to give up aws-exports functionality.

Reproduction steps

See above

Build Settings

version: 1
backend:
  phases:
    build:
      commands:
        - amplifyPush --simple
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
    build:
...

Additional information

A simple workaround could be to add [skip backend] to commit messages option. Just like how we can add [skip-cd].

Voyager-Two avatar Aug 10 '22 16:08 Voyager-Two

Hi @Voyager-Two I'm able to successfully use the AMPLIFY_DIFF_BACKEND variable and see that it is working. Can you please provide your app ID so we can further investigate the behavior?

ghost avatar Aug 10 '22 22:08 ghost

@hloriana I don't feel comfortable providing the App ID in a public forum. What does your amplify.yml look like while testing?

I'm guessing the issue is, if deploying to different environment, when you run amplifyPush --simple it modifies contents of amplify dir during backend build to adjust contents for new environment. Hence it resulting in different "diff".

For example: amplify folder contains config based on main Amplify env, but you are deploying to staging Amplify env.

Voyager-Two avatar Aug 12 '22 17:08 Voyager-Two

Hi @Voyager-Two it looks like you set the environment variable correctly but Amplify is somehow not detecting it. Unfortunately I still haven't been able to reproduce this behavior even with just running amplifyPush --simple.

Can you:

  • confirm if this is happening in multiple apps or just this one app
  • try setting the AMPLIFY_SKIP_BACKEND_BUILD to true and confirm if your backend builds can be skipped with this variable instead

ghost avatar Sep 01 '22 20:09 ghost

Hi @hloriana, thanks for the follow-up.

  • We only have one app.
  • Setting AMPLIFY_SKIP_BACKEND_BUILD to true does not work either, it still runs the build.

image

Voyager-Two avatar Oct 05 '22 15:10 Voyager-Two

Just as an additional point, I have this enabled, which probably affects it. image

Enable full-stack continuous deployments (CI/CD) Full-stack CI/CD allows you to continously deploy frontend and backend changes on every code commit

Voyager-Two avatar Oct 05 '22 15:10 Voyager-Two

I have a related question. When using AMPLIFY_DIFF_BACKEND can we still use amplifyPush --simple as part of the backend build? I get the sense that there can't be any commands whatsoever in the build phase. I suppose it would help if custom commands can be defined more clearly here states https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html

where the docs state:

If you currently have custom commands specified in the build settings of your backend phase, conditional backend builds won't work. If you want those custom commands to run, you must move them to the frontend phase of your build settings in your app's amplify.yml file.

oste avatar Nov 17 '22 04:11 oste

I should follow up, if we can't use amplifyPush --simple as part of the build command with AMPLIFY_DIFF_BACKEND how should we go about deploying backend resources conditionally?

oste avatar Nov 19 '22 14:11 oste

@oste Yes you should be able to use amplifyPush --simple in backend build according to docs. But there seems to be a (edge case) bug where it always does backend build even if there are no changes in amplify directory.

Had the thought the other day it could be related to Lambda layers creating new versions every build https://github.com/aws-amplify/amplify-cli/issues/11144

So it infers amplify dir has changed because of that bug, even if it hasn't.

Voyager-Two avatar Jan 30 '23 16:01 Voyager-Two