001/* 002 * Copyright 2019 Perihelios LLC 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package com.perihelios.aws.lambda.cloudwatch.dispatcher.event; 017 018import java.time.ZonedDateTime; 019import java.util.List; 020 021import static java.util.Collections.emptyList; 022 023/** 024 * Encapsulates the metadata from a CloudWatch event. 025 * <p> 026 * Every CloudWatch event includes a set of common fields; this class encapsulates those. 027 * </p> 028 * <p> 029 * Note that the {@code detail-type} property is not included in this class, as it is used exclusively by the 030 * unmarshaller to identify to which subtype of {@link CloudWatchEvent} the event should be unmarshalled. The 031 * {@code detail} property is unmarshalled as the body of the identified subtype, and so is also not included in the 032 * header. 033 * </p> 034 */ 035@SuppressWarnings("unused") 036public class Header { 037 private String version; 038 private String id; 039 private String source; 040 private String account; 041 private ZonedDateTime time; 042 private String region; 043 private List<String> resources = emptyList(); 044 045 /** 046 * Returns the CloudWatch event version. 047 * <p> 048 * At this time, the version is always {@code "0"}. 049 * </p> 050 * 051 * @return the event version 052 */ 053 public String version() { 054 return version; 055 } 056 057 /** 058 * Returns the unique CloudWatch event ID. 059 * 060 * @return the event ID 061 */ 062 public String id() { 063 return id; 064 } 065 066 /** 067 * Returns the AWS service name that is the source of the event. 068 * 069 * @return the event source 070 */ 071 public String source() { 072 return source; 073 } 074 075 /** 076 * Returns the AWS account ID for which the event was generated. 077 * 078 * @return the AWS account ID 079 */ 080 public String account() { 081 return account; 082 } 083 084 /** 085 * Returns the timestamp when the event occurred. 086 * <p> 087 * The resolution of this field is typically only to the second. Specific events may provide higher-resolution 088 * timestamps as part of their bodies. 089 * </p> 090 * 091 * @return the event timestamp 092 */ 093 public ZonedDateTime time() { 094 return time; 095 } 096 097 /** 098 * Returns the AWS region where the event occurred. 099 * 100 * @return the event region 101 */ 102 public String region() { 103 return region; 104 } 105 106 /** 107 * Returns the AWS resources (typically, ARNs) affected by the event. 108 * 109 * @return the resources affected by the event 110 */ 111 public List<String> resources() { 112 return resources; 113 } 114}