amplify-hosting
amplify-hosting copied to clipboard
AMPLIFY_DIFF_BACKEND does not work
Before opening, please confirm:
- [X] I have checked to see if my question is addressed in the FAQ.
- [X] I have searched for duplicate or closed issues.
- [X] I have read the guide for submitting bug reports.
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
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_BACKENDset totrue.- No code changes to
amplifydirectory. - With no custom
backendcommands inamplify.yml(apart fromamplifyPush --simple)
This often adds 4 min unnecessary overhead to builds.

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


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].
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?
@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.
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_BUILDtotrueand confirm if your backend builds can be skipped with this variable instead
Hi @hloriana, thanks for the follow-up.
- We only have one app.
- Setting
AMPLIFY_SKIP_BACKEND_BUILDtotruedoes not work either, it still runs the build.

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

Enable full-stack continuous deployments (CI/CD) Full-stack CI/CD allows you to continously deploy frontend and backend changes on every code commit
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.
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 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.