aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.81k stars 819 forks source link

updating custom-policies.json on function doesn't update function #10907

Open joekiller opened 2 years ago

joekiller commented 2 years ago

Before opening, please confirm:

How did you install the Amplify CLI?

npm

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

v16.16.0

Amplify CLI Version

9.2.1

What operating system are you using?

Arch Linux

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

No manual changes made

Amplify Categories

function

Amplify Commands

push

Describe the bug

I updated the custom-policies.json and amplify push didn't register the change.

Expected behavior

I expected the custom policy to be applied to the cloudformation.

Reproduction steps

  1. Create a function
  2. Push function
  3. Update custom-policies.json
  4. Push

GraphQL schema(s)

```graphql # Put schemas below this line ```

Project Identifier

No response

Log output

``` # Put your logs below this line ```

Additional information

No response

ykethan commented 2 years ago

Hey @joekiller, thank you for reaching out. I tried replicating the lambda function in my Amplify application but was unable to reproduce the issue.

Steps utilized:

  1. Created a NodeJs function
  2. Ran amplify push
  3. updated the custom-polices.json
  4. ran amplify push
  5. observed changes in Lambda function role document

image

image

Could you let us know what runtime was utilized when the lambda function was created?

joekiller commented 2 years ago

By runtime do you mean what lambda runtime? It was a nodejs function. When I encountered this is was somewhat of a revert. So maybe that part is what is missing? Ie maybe try:

  1. Create a NodeJs function
  2. run amplify push
  3. update the custom-polices.json
  4. run amplify push
  5. remove custom-policies.json
  6. run amplify push
  7. add same policy back.
  8. run amplify push and it'll report no changes.

if you cannot replicate after that I guess we can just close this.

ykethan commented 2 years ago

Hey @joekiller, Thank you for the information. On further testing I observed that amplify CLI shows the status as no change when we modify the custom-policies.json when a push is currently occurring.

Reproduction steps:

  1. amplify add function select NodeJs runtime.
  2. amplify push
  3. while the push is occurring update the custom-polices.json
  4. amplify status (this should show as no change)

Thank you for reporting. marking this as bug for further investigation.

josefaidt commented 2 years ago

Note for fix: this is likely due to this file not being tracked as a part of the collection used to determine resource state

josefaidt commented 2 years ago

The workaround to this issue would be to make a small update to the source code (e.g. add a newline to src/index.js) or use --force with amplify push

joekiller commented 2 years ago

@josefaidt thanks for noting a workaround. I'll keep it in mind if I find myself in the situation again.

shgamedev commented 3 months ago

@josefaidt the workaround is not working for me. I can see that a new function created in the CLI is not creating a CustomLambdaExecutionPolicy entry in the function's generated cloudformation-template.json.