Skip to content

CloudWatchEvent not populating for scheduled rule. #112

Open
@phcyso

Description

@phcyso

Should the events.CloudWatchEvent type populate for scheduled cloudwatch events?

I have three cloudwatch events running on a schedule with different values set for the detail value.
The idea is to have one lambda function do three different tasks as they have a lot of shared code.
however the events.CloudWatchEvent struct is being passed to my handler empty.

Is there something else I need to do to get this to populate or is it just not set when using scheduled events?

Cloudwatch logs:

START RequestId: 9c1f6e4f-afef-11e8-a063-7369fa288f45 Version: $LATEST
2018/09/04 03:07:09 Starting check in , in account:
2018/09/04 03:07:09 Raw event Data: { 0001-01-01 00:00:00 +0000 UTC [] []}
2018/09/04 03:07:09 Raw event detail:
END RequestId: 9c1f6e4f-afef-11e8-a063-7369fa288f45 

Code that gets called:

func main() {
	lambda.Start(HandleRequest)
}
func HandleRequest(event events.CloudWatchEvent) {
	var awsObjects types.AssuranceCheckList
	var err error

	checkStartTime := time.Now()
	log.Printf("Starting check in %v, in account: %v", event.Region, event.AccountID)
	log.Printf("Raw event Data: %v", event)
	log.Printf("Raw event detail: %v", string(event.Detail))
	var eventDetails types.EventDetail
	jsonErr := json.Unmarshal(event.Detail, &eventDetails)
	if jsonErr != nil {
		panic(err) // This is where it is being killed
	}
	log.Printf("Type of event is: %v", eventDetails.Type)
...
}

Creating a test event works as expected:
Test event data:

{
  "account": "0123456789",
  "region": "us-west-2",
  "detail": {
    "type": "rds"
  },
  "detail-type": "Scheduled Event",
  "source": "aws.events",
  "time": "1970-01-01T00:00:00Z",
  "id": "cdc73f9d-aea9-11e3-9d5a-835b769c0d9c",
  "resources": [
    "arn:aws:events:us-west-2:0123456789:rule/RdsCheck"
  ]
}

Log output:

START RequestId: f947eb4f-afed-11e8-802f-e5580a33f9b3 Version: $LATEST
2018/09/04 02:55:26 Starting Backup assurance check in us-west-2, in account: 0123456789
2018/09/04 02:55:26 Raw event Data: { cdc73f9d-aea9-11e3-9d5a-835b769c0d9c Scheduled Event aws.events 0123456789 1970-01-01 00:00:00 +0000 UTC us-west-2 [arn:aws:events:us-west-2:0123456789:rule/RdsCheck] [123 34 116 121 112 101 34 58 34 114 100 115 34 125]}
2018/09/04 02:55:26 Raw event detail: {"type":"rds"}
2018/09/04 02:55:26 Type of event is: rds
2018/09/04 02:55:26 About to do some RDS Related stuff!
2018/09/04 02:55:27 No Objects Found for alerting
END RequestId: f947eb4f-afed-11e8-802f-e5580a33f9b3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions