amplify-cli
amplify-cli copied to clipboard
Feature request to reference multiple categories of same type in custom CDK created by amplify add custom
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
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",
});
Could you provide us some additional information on the behavior you are observing? are you observing any error messages?
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.
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.
-
amplify add storage
-> dynamoDB - selected yes to trigger
-
amplify push
-
amplify add custom
with dependancy on Lambda trigger function and other resources
[
{
category: "function",
resourceName: "lamdbauuthce7a59d9",
},
{
category: "function",
resourceName: "lamdbauuth5b581962",
},
{
category: "function",
resourceName: "dynamoeaeec0d5Trigger0f90e63b",
},
]
-
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 runningamplify build
to build locally and check for any errors?
Closing the issue due to inactivity. Do reach out to us if you are still experiencing this issue
This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.