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.59k stars 3.89k forks source link

Add code commit to lambda trigger to CDK #24414

Open aurelien-leloup opened 1 year ago

aurelien-leloup commented 1 year ago

Describe the feature

On the AWS console, it is possible to create a trigger from a CodeCommit repository to a Lambda Function. I would like to be able to do it, with the same level of configuration through the CDK.

Use Case

Unless I am mistaken, this is not possible to do from the CDK. I have seen something using EventBridge. But it is not the same.

Proposed Solution

I am thinking that the easiest way to do this would be to add CodeCommit as a possible EventSource for lambda fuctions.

Other Information

No response

Acknowledgements

CDK version used

2.66.1

Environment details (OS name and version, etc.)

not relevant

pahud commented 1 year ago

Hi,

You actually can use repo.onXxxx() to listen on specific events and push to arbitrary event targets as described in the README. Can you elaborate why it doesn't work for you?

aurelien-leloup commented 1 year ago

Hello, Yes, I have noticed those methods and tried to use them, but it does not work for me. They use EventBridge to trigger the lambda. The triggering part works fine, but then my lambda expects a CodeCommitEvent and cannot interpret this.

So, I am left with two bad options :

pahud commented 1 year ago

Yes when you specify repo.onXxxx(), your lambda function will receive events from the event bridge and you will need to parse the CodeCommitEvent in your lambda function.

Is there something missing from the CodeCommitEvent and your lambda func just can't work with it?

github-actions[bot] commented 1 year ago

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.

aurelien-leloup commented 1 year ago

EventBridge works fine for that use case, there is no problem with it. It is a fine workaround for most people looking for triggering lambda from the CDK.

However, it is still a workaround. In the AWS Console you can trigger a lambda directly from CodeCommit (see image). This alone justifies the feature request.

I understand my use case is very specific. As I am not authorized to use EventBridge in my organization, I have to configure the lambda manually.

image

adamjkeller commented 1 day ago

We should close this issue as CodeCommit is no longer taking new customers and eventually will be deprecated. See here: https://aws.amazon.com/blogs/devops/how-to-migrate-your-aws-codecommit-repository-to-another-git-provider/

@pahud