aws-amplify / aws-amplify/amplify-cli

Cannot add S3 bucket name env var to Lambda fn due to cyclic dependency with S3 storage

Open
#10,278 6 comments 0 reactions 0 assignees View on GitHub
bug ops-errors p2 storage
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

### Before opening, please confirm:

- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-cli/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-cli/blob/master/CONTRIBUTING.md#bug-reports).
- [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.

### How did you install the Amplify CLI?

npm

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

14.17.6

### Amplify CLI Version

8.0.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.

no

### Amplify Categories

storage, function

### Amplify Commands

update

### Describe the bug

I added an S3 Trigger from my storage category to a new lambda function.

I then gave read access to the lambda to the same storage category, and I got a cyclic dependency error, but amplify still did some changes and everything seems to be working correctly.

### Expected behavior

No error when giving lambda read access to storage category that has trigger to the same lambda.

### Reproduction steps

1. Create lambda fn
2. Setup storage category with a trigger to that lambda fn
3. Then do the following:

```
hisham@mb3 ess-app % amplify update function
? Select which capability you want to update: Lambda function (serverless function)
? Select the Lambda function you want to update EssS3TriggerFn
General information
- Name: EssS3TriggerFn
- Runtime: nodejs

Resource access permission
- Not configured

Scheduled recurring invocation
- Not configured

Lambda layers
- essappCliLambdaLayer

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. storage
? Storage has 8 resources in this project. Select the one you would like your Lambda to access EssUsersS3
? Select the operations you want to permit on EssUsersS3 read

You can access the following resource attributes as environment variables from your Lambda function
STORAGE_ESSUSERSS3_BUCKETNAME
Error: Cannot add EssS3TriggerFn due to a cyclic dependency
at checkForCyclicDependencies (/snapshot/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/update-amplify-meta.js:246:15)
at AmplifyToolkit.updateamplifyMetaAfterResourceUpdate [as _updateamplifyMetaAfterResourceUpdate] (/snapshot/node_modules/@aws-amplify/cli-internal/lib/extensions/amplify-helpers/update-amplify-meta.js:154:9)
at updateFunctionResource (/snapshot/node_modules/amplify-category-function/lib/provider-utils/awscloudformation/index.js:157:29)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at Object.executeAmplifyCommand (/snapshot/node_modules/amplify-category-function/lib/index.js:262:5)
at executePluginModuleCommand (/snapshot/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:142:5)
at executeCommand (/snapshot/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:40:9)
at Object.run (/snapshot/node_modules/@aws-amplify/cli-internal/lib/index.js:160:9)
```

### GraphQL schema(s)

```graphql
# Put schemas below this line

```

### Log output

```
# Put your logs below this line

```

### Additional information

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with `amplify update function` after configuring an S3 trigger and storage read access. Start with `checkForCyclicDependencies` in `update-amplify-meta.js` and `updateFunctionResource` in `amplify-category-function`; done means the access update completes without the cyclic-dependency error and the bucket-name environment variable is available.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, typescript
Domain
cli, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.