DennoVonDiesel / tf

Apache License 2.0
0 stars 4 forks source link

UnmarshalTypeError - Error running in lambda #1

Open JonLittleIT opened 4 years ago

JonLittleIT commented 4 years ago

hey can you help me look at this issue in the code?

{ "errorMessage": "json: cannot unmarshal array into Go struct field CloudWatchEvent.detail-type of type string", "errorType": "UnmarshalTypeError" }

which is related to this func

func handler(event events.CloudWatchEvent) error { var finding GuardDutyFinding err := json.Unmarshal(event.Detail, &finding) if err != nil { log.Fatalf("Cannot unmarshal finding: %v", err) }

type GuardDutyFinding struct { ID string json:"id" Title string json:"title" Description string json:"description" Severity float32 json:"severity" Type string json:"type" AccountId string json:"accountId" }

any idea why I cant get this to run in Lambda?

DennoVonDiesel commented 4 years ago

Did you run the terraform to create the aws_cloudwatch_event_rule of type GuardDuty? Can you view it from the console?

JonLittleIT commented 4 years ago

I wanted to test just the lambda and I manually created the cloud watch rule which is set to trigger lambda on Guard Duty findings in Cloudwatch.

DennoVonDiesel commented 4 years ago

Without the filter for GuardDuty finding events you'll get CloudWatch events that the Lambda cannot process. It was only intended to process those of type GuardDuty.