aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.57k stars 3.88k forks source link

(lambda-event-sources): Validate that SQS Queue visibility timeout is larger than Lambda function timeout #20527

Open Gtofig opened 2 years ago

Gtofig commented 2 years ago

Describe the feature

Validate that SQS Queue visibility timeout is larger than Lambda function timeout when adding SQS queue as event source to Lambda.

Use Case

When adding SQS as event source to Lambda, AWS requires Queue visibility timeout to be larger than Lambda timeout, otherwise CloudFormation deployment will fail. At the moment, developer will only find out about this issue during deployment. Instead, CDK should fail at synthesis time if timeout condition is not satisfied.

Proposed Solution

I had a quick look at the code, and it's not immediately obvious how to implement this, because the place where binding happens uses IFunction interface, which does not expose timeout property.

If we could add timeout property to IFunction, then validation could be done in the bind method of the SqsEventSource class linked above.

I'm happy to implement the fix, but want to hear what people think the right way to implement it would be.

Other Information

No response

Acknowledgements

CDK version used

1.157.0

Environment details (OS name and version, etc.)

Ubuntu 20

markmansur commented 2 years ago

I don't see an issue with adding an optional timeout? property to IFunction.

I'll let one of the CDK maintainers comment. I have been a bit confused trying to understand why some properties are omitted in the resource interface, but present in the construct class.

otaviomacedo commented 2 years ago

Hi, @markmansur. Adding a timeout? property to IFunction seems appropriate in this case. Feel free to submit a PR to address this issue.

Gtofig commented 2 years ago

I've created PR, which attempts to address this issue: https://github.com/aws/aws-cdk/pull/21272