Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request to reference multiple categories of same type in custom CDK created by amplify add custom #13743

Open
2 tasks
mahimc367 opened this issue Apr 27, 2024 · 3 comments
Labels
custom-cdk Issues related to custom CDK resource functionality pending-response Issue is pending response from the issue author pending-triage Issue is pending triage

Comments

@mahimc367
Copy link

mahimc367 commented Apr 27, 2024

Is this feature request related to a new or existing Amplify category?

Amplify add custom

Is this related to another service?

categories

Describe the feature you'd like to request

Hello Team,

There is a current limitation with Amplify where in custom resources we can not reference multiple categories of the same type. Hence, would like to have this feature. To be more elaborative as an example,

Let's say we set 2 storage categories here , one being DynamoDB and another being S3.

    const dependencies: AmplifyDependentResourcesAttributes = AmplifyHelpers.addResourceDependency(this,

      amplifyResourceProps.category,
    
      amplifyResourceProps.resourceName,
    
      [{
    
        category: "storage", // api, auth, storage, function, etc.
    
        resourceName: "s3adb460b9" // find the resource at "amplify/backend/<category>/<resourceName>"
    
      } ,
      {
        "category": "storage",
        "resourceName": "dynamof7a3661d"
      },
    {
      category: "function", // api, auth, storage, function, etc.
    
      resourceName: "S3Trigger73aadd3a" 
    },
    {
      category: "function",
      resourceName: "dynamof7a3661dTrigger8e29c4d0"

    }
  ] 

However, we can not reference the same as

 const s3bucketname = cdk.Fn.ref(dependencies.storage.s3adb460b9.BucketName)
const dynamodbstreamarn = cdk.Fn.ref(dependencies.storage.dynamof7a3661d.StreamArn)

Describe the solution you'd like

Current Solution: To create multiple custom resources for each storage category

Describe alternatives you've considered

NA

Additional context

No response

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request

Would this feature include a breaking change?

  • ⚠️ This feature might incur a breaking change
@mahimc367 mahimc367 added the pending-triage Issue is pending triage label Apr 27, 2024
@ykethan
Copy link
Contributor

ykethan commented Apr 29, 2024

Hey @mahimc367, thank you for reaching.Tried reproducing the issue using the following but did observe the references being populated.

 const dependencies: AmplifyDependentResourcesAttributes =
      AmplifyHelpers.addResourceDependency(
        this,
        amplifyResourceProps.category,
        amplifyResourceProps.resourceName,
        [
          {
            category: "storage",
            resourceName: "s31e9ac140",
          },
          {
            category: "storage",
            resourceName: "dynamo998b10f3",
          },
          {
            category: "function",
            resourceName: "lamdbauth99b65c27",
          },
        ]
      );

    console.log(dependencies);
    const s3bucketName = cdk.Fn.ref(dependencies.storage.s31e9ac140.BucketName);
    const dynamoTableName = cdk.Fn.ref(
      dependencies.storage.dynamo998b10f3.Name
    );
    const functionName = cdk.Fn.ref(
      dependencies.function.lamdbauuth99b65c27.Name
    );
    new cdk.CfnOutput(this, "s3bucketName", {
      value: s3bucketName,
      description: "The name of the S3 bucket",
    });
    new cdk.CfnOutput(this, "dynamoTableName", {
      value: dynamoTableName,
      description: "The name of the DynamoDB table",
    });
    new cdk.CfnOutput(this, "functionName", {
      value: functionName,
      description: "The name of the Lambda function",
    });

image

Could you provide us some additional information on the behavior you are observing? are you observing any error messages?

@ykethan ykethan added pending-response Issue is pending response from the issue author custom-cdk Issues related to custom CDK resource functionality labels Apr 29, 2024
@mahimc367
Copy link
Author

Hello Team,

I observe error "Cannot read properties of undefined (reading 'Arn')" when pushing the stack which means that the code is trying to reference/access a property or function on a value that is not assigned.

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Apr 30, 2024
@ykethan
Copy link
Contributor

ykethan commented Apr 30, 2024

Hey @mahimc367, was the Lambda resource pushed before adding the dependancy in the custom cdk resource?
tried reproducing the issue on the latest Amplify CLI version but did not observe this error message.

  1. amplify add storage -> dynamoDB
  2. selected yes to trigger
  3. amplify push
  4. amplify add custom with dependancy on Lambda trigger function and other resources
[
          {
            category: "function",
            resourceName: "lamdbauuthce7a59d9",
          },
          {
            category: "function",
            resourceName: "lamdbauuth5b581962",
          },
          {
            category: "function",
            resourceName: "dynamoeaeec0d5Trigger0f90e63b",
          },
        ]
  1. amplify push
    does the steps align with the current resource setup? if not could you provide additional information on the steps utilized.
    Could you try running amplify build to build locally and check for any errors?

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
custom-cdk Issues related to custom CDK resource functionality pending-response Issue is pending response from the issue author pending-triage Issue is pending triage
Projects
None yet
Development

No branches or pull requests

2 participants