Class CloudWatchEvent


  • public class CloudWatchEvent
    extends Object
    Base class of all CloudWatch events.

    CloudWatch events are delivered to AWS Lambda functions as JSON documents. There are a small number of top-level properties in the JSON; these are mostly metadata, and are unmarshalled into the Header, obtainable via header(). The event proper is contained in the detail property, with the detail-type property providing a way to identify what properties may be expected in detail.

    Subclasses should always be annotated with DetailType, as this is the only mechanism to indicate to which subclass an event should be unmarshalled. Assume an event such as this is received by an AWS Lambda:

         {
             ...
             "detail-type": "Some Service Event",
             "detail": {
                 "blah": "some value",
                 "foo": 17
             }
             ...
         }

    A proper class to which to unmarshal this event might look like this:

            @DetailType("Some Service Event")
            class MyCustomEvent extends CloudWatchEvent {
                private String blah;
                private int foo;
    
                String blah() {
                    return blah;
                }
    
                int foo() {
                    return foo;
                }
            }
     

    Note that MyCustomEvent would also need to be registered with CloudWatchEventDispatcher.withEventHandler() in order to be used during event dispatch.

    • Method Detail

      • header

        public Header header()
        Returns the header (metadata) from the event.
        Returns:
        the event header
      • setHeader

        public void setHeader​(Header header)
        Sets the header (metadata) on the event.
        Parameters:
        header - the event header to set