AWS CodeCommit events sent from EventBridge are not received
- Dominant language
- Go
- Stars
- 3.8k
- Forks
- 578
- Avg merge
- 8h 18m
- Merged PRs (30d)
- 1
Description
This issue is mainly to address the generalization of the `Detail` available in a given [`events.CloudWatchEvent`](https://github.com/aws/aws-lambda-go/blob/master/events/cloudwatch_events.go) and some duplicate code that I noticed.
**Is your feature request related to a problem? Please describe.**
The current [AWS Codecommit types](https://github.com/aws/aws-lambda-go/blob/master/events/code_commit.go) do not match events sent from EventBridge, because they are made for a direct CodeCommit to Lambda integration. [There are ***24*** unique events](https://docs.aws.amazon.com/codecommit/latest/userguide/monitoring-events.html) that can be sent from an EventBridge CodeCommit rule to a source Lambda function. The events take the structure of [`events.CloudWatchEvent`](https://github.com/aws/aws-lambda-go/blob/master/events/cloudwatch_events.go), but the `Detail`s of the events vary.
For example, given this EventBridge event rule (all events from CodeCommit in a particular AWS region):
```json
{
"source": [
"aws.codecommit"
]
}
```
...and this Lambda function signature, similarly documented [here](https://github.com/aws/aws-lambda-go/blob/master/events/README_CodeCommit.md):
```go
func SomeHandler(evt events.CodeCommitEvent) error {
// Handler logic here
return nil
}
```
None of the records are correctly unmarshalled because they do not match this type (again since this is for a direct CodeCommit to Lambda trigger).
**Describe the solution you'd like**
I would consider adding the correct types to encapsulate the data sent from the EventBridge CodeCommit rules after they are matched by [`events.CloudWatchEvent`](https://github.com/aws/aws-lambda-go/blob/master/events/cloudwatch_events.go). I don't know what the best way to do this would be since I can't find any documentation on what the behavior is for certain events. For example, if I push ten commits to my CodeCommit repo, will those commits be encapsulated within one event's details or will EventBridge fire ten different events to my function?
I would also consider adding documentation to direct customers to use [`events.CloudWatchEvent`](https://github.com/aws/aws-lambda-go/blob/master/events/cloudwatch_events.go) when working with events from EventBridge. This would be more of a temporary solution.
I imagine the best solution scales to ALL Eventbridge source rules, not just CodeCommit.
Also, it looks like there was a [related change](https://github.com/aws/aws-lambda-go/pull/23/commits/92bc2dd27103fafa8ca67723d98ead994a2b87f0) to add Autoscaling related events as well. [`events.AutoScalingEvent`](https://github.com/aws/aws-lambda-go/blob/master/events/autoscaling.go) matches the structure of [`events.CloudWatchEvent`](https://github.com/aws/aws-lambda-go/blob/master/events/cloudwatch_events.go) almost exactly, so I'm not sure what happened there. The detail is also being accessed as a `map[string]string` and this could have been accomplished with [`events.CloudWatchEvent`](https://github.com/aws/aws-lambda-go/blob/master/events/code_commit.go) where `Detail` is a `json.RawMessage`.
The most ideal solution also prevents manually adding types for ***every*** service that integrates with Events (EventBridge/CloudWatch Events).
**Describe alternatives you've considered**
I've considered creating all of these structs and switching on the current CloudWatchEvent, but this would take a lot of development overhead. Making a separate package for these types, or the details returned by EventBridge AWS Service events, could become a lot of work.
Generating structures for the event details based on some sort of model or schema may also be a possibility.
**Additional context**
For context, I'm creating a Lambda function that posts CodeCommit events to a [Discord](https://discordapp.com/) server via webhook. Running a switch statement on the 24 types of events is not the issue, but structuring the details of those 24 events is.
Contributor guide
Assessment
This issue has not been assessed yet.