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: provider-framework ignores Status response from user lambdas #27208

Closed
ckenna opened this issue Sep 20, 2023 · 3 comments
Closed
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources bug This issue is a bug. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@ckenna
Copy link

ckenna commented Sep 20, 2023

Describe the bug

There is (IMO) a bug in the custom resource provider framework CDK code here.

This custom resource provider function calls my user defined Lambda and gets a result back. My user Lambda can fail, and when it does it returns a JSON object that contains { "Status": "FAILED" } (this is even in the object on line 37). But, then this CDK provider framework code ignore this status on line 43 and sends SUCCESS back which does not fail the deployment. The same happens on line 86, too, but that's not my codepath.

Expected Behavior

I expect the status to be equal to the one in my Lambda response, which may be 'FAILED'. This should fail the deployment.

Current Behavior

The response is hard coded as 'SUCCESS' and the deployment will always succeed.

Reproduction Steps

Create a Lambda that always replies with the { "Status": "FAILED" } and use it in a custom resource like this, then deploy the stack. It will succeed.

        this.provider = new Provider(this, `MyProvider`, {
            onEventHandler: this.myLambda,
            logRetention: RetentionDays.ONE_YEAR,
        });
        this.customResource = new CustomResource(this, `MyCustomResource`, {
            serviceToken: this.provider.serviceToken,
            properties: {
                // This executes the lambda every deployment
                deployDate: new Date().toISOString(),
            },
        });

Possible Solution

Honor the response from the Lambda.

Additional Information/Context

No response

CDK CLI Version

2.95.1 (build ae455d8)

Framework Version

No response

Node.js Version

18.16.0

OS

Linux

Language

Typescript

Language Version

No response

Other information

No response

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

pahud commented Sep 20, 2023

Specifically, to report success or failure, have your Lambda Function exit in the right way: return data for success, or throw an exception for failure. Do not post the success or failure of your custom resource to an HTTPS URL as the CloudFormation documentation tells you to do.
https://github.com/aws/aws-cdk/tree/main/packages/aws-cdk-lib/custom-resources#provider-framework

I believe you will need to throw an error in your lambda function based on the description in the doc.

@pahud pahud added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Sep 20, 2023
@ckenna
Copy link
Author

ckenna commented Sep 20, 2023

Interesting! Thank you I'll do that instead. You can close this bug. I was using an internal library at the company I work at, and I think maybe the library itself is outdated.

@ckenna ckenna closed this as completed Sep 20, 2023
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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. effort/medium Medium work item – several days of effort 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