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

AWS Amplify CLI always shows "update" when JSON files are formatted

Open hendrickson-tyler opened this issue 1 year ago • 3 comments

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

20.9.0

Amplify CLI Version

12.8.2

What operating system are you using?

macOS 14.1.1

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

All files not in the .gitignore were formatted using Prettier. This only updates whitespace, line breaks, and indentation. This was using the default Prettier settings with two overrides in the .prettierrc:

{
  "singleQuote": true,
  "useTabs": true
}

Describe the bug

We use Prettier in our development process to automatically keep our code formatting consistent. Amplify doesn't seem to behave correctly when backend JSON files are formatted in any way, shape, or form. After an amplify push, Amplify updates all of these files to some other format. At this point amplify status shows no changes. After formatting these changes with Prettier to bring everything back to the way it was when we pushed, amplify status will then show that everything is going to be updated again.

Because of this, every deployment in our CI/CD will update every API and Function unnecessarily.

Expected behavior

Amplify should not require JSON files to be in a certain format. So long as the JSON is valid, it should not modify files in any way—simply just deploy them.

Reproduction steps

  1. Create an empty Amplify project with amplify init
  2. Add a Lambda with amplify add function
  3. Format all code with npx prettier --write .
  4. Deploy with amplify push. Notice that the files have been un-formatted.
  5. amplify status shows no changes
  6. Format again with npx prettier --write .. Notice that this is exactly how it looked when we pushed earlier.
  7. Run amplify status. Once again shows that the function will be updated even though nothing has changed on our end.

Project Identifier

No response

Log output

No response

Additional information

Workarounds for this exist, but are not ideal. Options are

  • Require these JSON files to be in the format that Amplify wants before they are pushed
    • Breaks the uniformity of code styles in the project
    • Requires a separate config just for these JSON files
    • What is the format?
    • Impossible to use tabs instead of spaces
  • Push changed files after every amplify push to the originating branch
    • Not ideal to have your CI/CD making changes directly. It should simply deploy reproducibly and not make any development changes.

If I'm missing something, please let me know. I tried to find a similar issue, but was unable to find anything.

Before submitting, please confirm:

  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

hendrickson-tyler avatar Nov 30 '23 21:11 hendrickson-tyler

Hey @hendrickson-tyler, thank you for reaching out. This is currently the expected behaviour on push to ensure the templates have no errors at build time. On reaching out to the team, i was able to find that we can utilize .prettierignore at the root of the project with files you would like to not format on a push, which enable you to your expected styling.

On testing .prettierignore that has

amplify/backend/backend-config.json
amplify/backend/**/*-cloudformation-template.json
amplify/backend/types
amplify/team-provider-info.json 

there were no changes to the files on a push

Marking this as feature request.

ykethan avatar Dec 04 '23 18:12 ykethan

Thanks @ykethan! In the near term, we can certainly avoid formatting those files. However, even without utilizing a formatter, I think the same issue will likely crop up if one of our developers doesn't format the JSON in the way that Amplify wants. For example, a developer might add a line break somewhere that amplify push will want to change. If this happens, the "correct" format that Amplify wants won't ever be committed back to our development branch because we are only ever deploying through our CI/CD pipeline. This would result in the same problem—functions constantly showing as "update".

Ideally in the future, Amplify would validate the templates without deploying its own version of the changed files. Hoping this can be addressed in the near future! Happy to try and come up with a PR for review if it would help push things along.

hendrickson-tyler avatar Dec 04 '23 19:12 hendrickson-tyler

Same problem here. Given there are users that edit certain files under the amplify dir these will follow our coding style formatting and will automatically happen through CI/CD or tooling. The status always being "create" prevents us trusting the output when using it in automated checks as we have to work around it. Not the end of the world but annoying.

codenimble avatar Dec 16 '23 18:12 codenimble