aws-amplify / aws-amplify/amplify-cli
unexpected stack trace for cyclic dependency error when attempting to grant auth access to lambda
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### How did you install the Amplify CLI?
pnpm
### If applicable, what version of Node.js are you using?
18
### Amplify CLI Version
10.6.2
### What operating system are you using?
mac
### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
n/a
### Describe the bug
```
➜ amplify update function
? Select the Lambda function you want to update 928762ef6d3PostConfirmation
General information
- Name: 928762ef6d3PostConfirmation
- Runtime: nodejs
Resource access permission
- Not configured
Scheduled recurring invocation
- Not configured
Lambda layers
- Not configured
Environment variables:
- Not configured
Secrets configuration
- Not configured
? Which setting do you want to update? Resource access permissions
? Select the categories you want this function to have access to. auth
? Auth has 2 resources in this project. Select the one you would like your Lambda
to access 928762ef6d3
? Select the operations you want to permit on 928762ef6d3 read
You can access the following resource attributes as environment variables from your Lambda function
AUTH_928762EF6D3_USERPOOLID
Error: Cannot add 928762ef6d3PostConfirmation due to a cyclic dependency
at checkForCyclicDependencies (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/update-amplify-meta.js:248:15)
at AmplifyToolkit.updateamplifyMetaAfterResourceUpdate [as _updateamplifyMetaAfterResourceUpdate] (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/update-amplify-meta.js:155:9)
at updateFunctionResource (/snapshot/repo/build/node_modules/amplify-category-function/lib/provider-utils/awscloudformation/index.js:157:29)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Object.executeAmplifyCommand (/snapshot/repo/build/node_modules/amplify-category-function/lib/index.js:270:5)
at async executePluginModuleCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:142:5)
at async executeCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:40:9)
at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:119:5)
There was an error adding the function resource
```
### Expected behavior
instead of
```
Error: Cannot add 928762ef6d3PostConfirmation due to a cyclic dependency
at checkForCyclicDependencies (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/update-amplify-meta.js:248:15)
at AmplifyToolkit.updateamplifyMetaAfterResourceUpdate [as _updateamplifyMetaAfterResourceUpdate] (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/update-amplify-meta.js:155:9)
at updateFunctionResource (/snapshot/repo/build/node_modules/amplify-category-function/lib/provider-utils/awscloudformation/index.js:157:29)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Object.executeAmplifyCommand (/snapshot/repo/build/node_modules/amplify-category-function/lib/index.js:270:5)
at async executePluginModuleCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:142:5)
at async executeCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:40:9)
at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:119:5)
There was an error adding the function resource
```
```
Error: Cannot add 928762ef6d3PostConfirmation due to a cyclic dependency
```
additionally, it would be nice if this error were printed when validating the options selected, blocking us from proceeding to select a CRUD permission:
```
? Select the categories you want this function to have access to.
◯ api
❯◉ auth
◯ custom
◯ function
◯ storage
Unable to add auth due to a cyclic dependency
```
### Reproduction steps
1. `amplify init -y`
2. `amplify add auth` > manual configuration
3. accept most defaults, add a PostConfirmation trigger
4. update the PostConfirmation trigger with `amplify update function`
5. select Resource Access Permissions
6. attempt to grant auth read access
7. observe stack trace with error "There was an error adding the function resource"
### Project Identifier
_No response_
### Log output
```
# Put your logs below this line
```
### Additional information
_No response_
### 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.
Contributor guide
Research direction
Reproduce the flow through amplify update function and resource access permissions, then inspect checkForCyclicDependencies and updateamplifyMetaAfterResourceUpdate in amplify-helpers/update-amplify-meta.js, plus updateFunctionResource in the function provider. Done means the CLI reports the cyclic-dependency error without an unexpected stack trace and, where possible, rejects the selection during validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, node.js, typescript
- Domain
- authentication, backend, cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100