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

(custom_resources): How to break a cross-stack dependency #26758

Closed
pb8o opened this issue Aug 15, 2023 · 5 comments
Closed

(custom_resources): How to break a cross-stack dependency #26758

pb8o opened this issue Aug 15, 2023 · 5 comments
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@pb8o
Copy link

pb8o commented Aug 15, 2023

Describe the bug

Hi, I have 2 stacks where one depends on the custom resource function of another.

Stack A has this

const myProvider = new cr.Provider(this, 'MyProvider', {onEventHandler: myFn});

It has an output like (edited):

MyStack:ExportsOutputFnGetAttMyProviderframeworkonEvent60E6A034ArnCBF1E63C

Stack B gets passed myProvider as a parameter and has this

myCR = new core.CustomResource(this, 'Sync', {
            serviceToken: myProvider.serviceToken,
            properties: {...}
}

I am now trying to break the relationship between the two, but it I am blocked since there is no direct access to the CDK-generated Lambda.

Expected Behavior

this.exportValue(myProvider);

Current Behavior

Error: exportValue: either supply 'name' or make sure to export a resource attribute (like 'bucket.bucketName')

Reproduction Steps

const myProvider = new cr.Provider(this, 'MyProvider', {onEventHandler: myFn});

Possible Solution

Would it be as easy as exposing this as a property of Provider?

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/custom-resources/lib/provider-framework/provider.ts#L181

Additional Information/Context

No response

CDK CLI Version

2.89.0

Framework Version

No response

Node.js Version

18

OS

Linux

Language

Typescript

Language Version

No response

Other information

No response

@pb8o pb8o added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 15, 2023
@github-actions github-actions bot added the @aws-cdk/custom-resources Related to AWS CDK Custom Resources label Aug 15, 2023
@pahud
Copy link
Contributor

pahud commented Aug 15, 2023

It's not clear to me where the error comes from.

Error: exportValue: either supply 'name' or make sure to export a resource attribute (like 'bucket.bucketName')

Do you mean the myProvider is in stack A but myFn is in stack B?

const myProvider = new cr.Provider(this, 'MyProvider', {onEventHandler: myFn});

Can you share the smallest code that represents both stacks and the their content?

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 15, 2023
@pb8o
Copy link
Author

pb8o commented Aug 15, 2023

Ok I updated the details of the issue. Sorry it is not very clear where the dependency is coming from. This is code I want to simplify.

Any help with a workaround would be very appreciated.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Aug 15, 2023
@pb8o
Copy link
Author

pb8o commented Sep 20, 2023

Ok I made some tiny progress. This is what I am trying to write for breaking the dependency:

        // to break the dependency, for the transition
        const ltSyncerFn = new lambda.Function(this, 'Sync Launch Template', {
            memorySize: 128, // MB
            timeout: core.Duration.seconds(60),
            runtime: lambda.Runtime.NODEJS_18_X,
            code: new lambda.InlineCode('foo'),
            handler: 'index.handler',
        });
        const ltSyncProvider = new cr.Provider(this, 'LaunchTemplateSyncProvider', {
            onEventHandler: ltSyncerFn,
        });
        this.exportValue(ltSyncProvider.entrypoint);

and this is what I get:

lib/imageBuilder.ts:196:41 - error TS2341: Property 'entrypoint' is private and only accessible within class 'Provider'.

196         this.exportValue(ltSyncProvider.entrypoint);
                                            ~~~~~~~~~~

Would it make sense to make that property public, so we can keep exporting it?

@pahud
Copy link
Contributor

pahud commented Sep 20, 2023

const ltSyncProvider = new cr.Provider(this, 'LaunchTemplateSyncProvider', {
            onEventHandler: ltSyncerFn,
        });
        this.exportValue(ltSyncProvider.entrypoint);

Why would you export the entrypoint?

It is actually private so you can't export it like that.

private readonly entrypoint: lambda.Function;

@pahud pahud added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 20, 2023
@github-actions
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants