aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
185 stars 62 forks source link

add resourceGroupName prop to function #2233

Closed rtpascual closed 6 days ago

rtpascual commented 1 week ago

Problem

Certain usage patterns with functions end up with Caused By: ❌ Deployment failed: Error [ValidationError]: Circular dependency between resources: ...

This happens in scenarios where it could be avoided if functions created with defineFunction were not in the same stack.

Issue number, if available:

Changes

Add resourceGroupName prop to defineFunction in order to provide the flexibility to designate a stack for a function resource.

Also introduces AmplifyResourceGroupName type which has default Amplify resource group names for each resource (example: defineData's resourceGroupName = 'data') that will show up in IntelliSense:

Screenshot 2024-11-14 at 4 36 49 PM

So with defineFunction it will be possible to:

Corresponding docs PR, if applicable:

Validation

Two new E2E test projects for common use cases that run into circular dependency issues: circular-dep-auth-data-func and circular-dep-data-func. I have them in two separate projects instead of one to isolate use cases. I also considered using TestProjectBase.getUpdates to swap out all files from one use case to another to keep things in one project but this will take longer to run.

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

changeset-bot[bot] commented 1 week ago

🦋 Changeset detected

Latest commit: 9c33558adbc11cc9ca1225774b1dde8ebff44624

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages | Name | Type | | ----------------------------- | ----- | | @aws-amplify/backend-function | Minor | | @aws-amplify/backend-storage | Patch | | @aws-amplify/plugin-types | Minor | | @aws-amplify/backend | Minor | | @aws-amplify/backend-auth | Patch | | @aws-amplify/backend-data | Patch | | @aws-amplify/backend-ai | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

josefaidt commented 6 days ago

cross-posting to main thread, for the jsdoc @default, is "function" a valid value? we can show the default is undefined if not https://github.com/aws-amplify/amplify-backend/pull/2233/files#diff-9e302baf9085cc0328df9e0e7779db3be80f85e6ec8157baffae911472642f51R30

sobolk commented 6 days ago

cross-posting to main thread, for the jsdoc @default, is "function" a valid value? we can show the default is undefined if not https://github.com/aws-amplify/amplify-backend/pull/2233/files#diff-9e302baf9085cc0328df9e0e7779db3be80f85e6ec8157baffae911472642f51R30

@josefaidt https://github.com/aws-amplify/amplify-backend/blob/f83d6d58cf9b167c6b4aa59e6be92ee4e9051ab5/packages/backend-function/src/factory.ts#L342