-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
events.go
336 lines (291 loc) · 9.11 KB
/
events.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2022-present Datadog, Inc.
// Package events provides a series of drop in replacements for
// "github.com/aws/aws-lambda-go/events". Using these types for json
// unmarshalling event payloads provides huge reduction in processing time.
// This means fewer map/slice allocations since only the fields which we will
// use will be unmarshalled.
package events
import (
"bytes"
"compress/gzip"
"encoding/base64"
"time"
"github.com/aws/aws-lambda-go/events"
json "github.com/json-iterator/go"
)
// APIGatewayProxyRequest mirrors events.APIGatewayProxyRequest type, removing
// unused fields.
type APIGatewayProxyRequest struct {
Resource string
Path string
HTTPMethod string
Headers map[string]string
RequestContext APIGatewayProxyRequestContext
}
// APIGatewayProxyRequestContext mirrors events.APIGatewayProxyRequestContext
// type, removing unused fields.
type APIGatewayProxyRequestContext struct {
Stage string
DomainName string
RequestID string
Path string
HTTPMethod string
RequestTimeEpoch int64
APIID string
}
// APIGatewayV2HTTPRequest mirrors events.APIGatewayV2HTTPRequest type,
// removing unused fields.
type APIGatewayV2HTTPRequest struct {
RouteKey string
Headers map[string]string
RequestContext APIGatewayV2HTTPRequestContext
}
// APIGatewayV2HTTPRequestContext mirrors events.APIGatewayV2HTTPRequestContext
// type, removing unused fields.
type APIGatewayV2HTTPRequestContext struct {
Stage string
RequestID string
APIID string
DomainName string
TimeEpoch int64
HTTP APIGatewayV2HTTPRequestContextHTTPDescription
}
// APIGatewayV2HTTPRequestContextHTTPDescription mirrors
// events.APIGatewayV2HTTPRequestContextHTTPDescription type, removing unused
// fields.
type APIGatewayV2HTTPRequestContextHTTPDescription struct {
Method string
Path string
Protocol string
SourceIP string
UserAgent string
}
// APIGatewayWebsocketProxyRequest mirrors
// events.APIGatewayWebsocketProxyRequest type, removing unused fields.
type APIGatewayWebsocketProxyRequest struct {
Headers map[string]string
RequestContext APIGatewayWebsocketProxyRequestContext
}
// APIGatewayWebsocketProxyRequestContext mirrors
// events.APIGatewayWebsocketProxyRequestContext type, removing unused fields.
type APIGatewayWebsocketProxyRequestContext struct {
Stage string
RequestID string
APIID string
ConnectionID string
DomainName string
EventType string
MessageDirection string
RequestTimeEpoch int64
RouteKey string
}
// APIGatewayCustomAuthorizerRequest mirrors
// events.APIGatewayCustomAuthorizerRequest type, removing unused fields.
type APIGatewayCustomAuthorizerRequest struct {
Type string
AuthorizationToken string
MethodArn string
}
// APIGatewayCustomAuthorizerRequestTypeRequest mirrors
// events.APIGatewayCustomAuthorizerRequestTypeRequest type, removing unused
// fields.
type APIGatewayCustomAuthorizerRequestTypeRequest struct {
MethodArn string
Resource string
HTTPMethod string
Headers map[string]string
RequestContext APIGatewayCustomAuthorizerRequestTypeRequestContext
}
// APIGatewayCustomAuthorizerRequestTypeRequestContext mirrors
// events.APIGatewayCustomAuthorizerRequestTypeRequestContext type, removing
// unused fields.
type APIGatewayCustomAuthorizerRequestTypeRequestContext struct {
Path string
}
// ALBTargetGroupRequest mirrors events.ALBTargetGroupRequest type, removing
// unused fields.
type ALBTargetGroupRequest struct {
HTTPMethod string
Path string
Headers map[string]string
RequestContext ALBTargetGroupRequestContext
}
// ALBTargetGroupRequestContext mirrors events.ALBTargetGroupRequestContext
// type, removing unused fields.
type ALBTargetGroupRequestContext struct {
ELB ELBContext
}
// ELBContext mirrors events.ELBContext type, removing unused fields.
type ELBContext struct {
TargetGroupArn string
}
// CloudWatchEvent mirrors events.CloudWatchEvent type, removing unused fields.
type CloudWatchEvent struct {
Resources []string
}
// CloudwatchLogsEvent mirrors events.CloudwatchLogsEvent type, removing unused
// fields.
type CloudwatchLogsEvent struct {
AWSLogs CloudwatchLogsRawData
}
// CloudwatchLogsRawData mirrors events.CloudwatchLogsRawData type, removing
// unused fields.
type CloudwatchLogsRawData struct {
Data string
}
// Parse returns a struct representing a usable CloudwatchLogs event
func (c CloudwatchLogsRawData) Parse() (d CloudwatchLogsData, err error) {
data, err := base64.StdEncoding.DecodeString(c.Data)
if err != nil {
return
}
zr, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
return
}
defer zr.Close()
dec := json.NewDecoder(zr)
err = dec.Decode(&d)
return
}
// CloudwatchLogsData mirrors events.CloudwatchLogsData type, removing unused
// fields.
type CloudwatchLogsData struct {
LogGroup string
}
// DynamoDBEvent mirrors events.DynamoDBEvent type, removing unused fields.
type DynamoDBEvent struct {
Records []DynamoDBEventRecord
}
// DynamoDBEventRecord mirrors events.DynamoDBEventRecord type, removing unused
// fields.
type DynamoDBEventRecord struct {
Change DynamoDBStreamRecord `json:"dynamodb"`
EventID string
EventName string
EventVersion string
EventSourceArn string
}
// DynamoDBStreamRecord mirrors events.DynamoDBStreamRecord type, removing
// unused fields.
type DynamoDBStreamRecord struct {
ApproximateCreationDateTime events.SecondsEpochTime
SizeBytes int64
StreamViewType string
}
// KinesisEvent mirrors events.KinesisEvent type, removing unused fields.
type KinesisEvent struct {
Records []KinesisEventRecord
}
// KinesisEventRecord mirrors events.KinesisEventRecord type, removing unused
// fields.
type KinesisEventRecord struct {
EventID string
EventName string
EventSourceArn string
EventVersion string
Kinesis KinesisRecord
}
// KinesisRecord mirrors events.KinesisRecord type, removing unused fields.
type KinesisRecord struct {
ApproximateArrivalTimestamp events.SecondsEpochTime
PartitionKey string
}
// EventBridgeEvent is used for unmarshalling a EventBridge event. AWS Go
// libraries do not provide this type of event for deserialization.
type EventBridgeEvent struct {
DetailType string `json:"detail-type"`
Source string
StartTime string
}
// S3Event mirrors events.S3Event type, removing unused fields.
type S3Event struct {
Records []S3EventRecord
}
// S3EventRecord mirrors events.S3EventRecord type, removing unused fields.
type S3EventRecord struct {
EventSource string
EventTime time.Time
EventName string
S3 S3Entity
}
// S3Entity mirrors events.S3Entity type, removing unused fields.
type S3Entity struct {
Bucket S3Bucket
Object S3Object
}
// S3Bucket mirrors events.S3Bucket type, removing unused fields.
type S3Bucket struct {
Name string
Arn string
}
// S3Object mirrors events.S3Object type, removing unused fields.
type S3Object struct {
Key string
Size int64
ETag string
}
// SNSEvent mirrors events.SNSEvent type, removing unused fields.
type SNSEvent struct {
Records []SNSEventRecord
}
// SNSEventRecord mirrors events.SNSEventRecord type, removing unused fields.
type SNSEventRecord struct {
SNS SNSEntity
}
// SNSEntity mirrors events.SNSEntity type, removing unused fields.
type SNSEntity struct {
MessageID string
Type string
TopicArn string
MessageAttributes map[string]interface{}
Timestamp time.Time
Subject string
}
// SQSEvent mirrors events.SQSEvent type, removing unused fields.
type SQSEvent struct {
Records []SQSMessage
}
// SQSMessage mirrors events.SQSMessage type, removing unused fields.
type SQSMessage struct {
ReceiptHandle string
Body string
Attributes map[string]string
MessageAttributes map[string]SQSMessageAttribute
EventSourceARN string
}
// SQSMessageAttribute mirrors events.SQSMessageAttribute type, removing unused
// fields.
type SQSMessageAttribute struct {
StringValue *string
BinaryValue []byte
DataType string
}
// LambdaFunctionURLRequest mirrors events.LambdaFunctionURLRequest type,
// removing unused fields.
type LambdaFunctionURLRequest struct {
Headers map[string]string
RequestContext LambdaFunctionURLRequestContext
}
// LambdaFunctionURLRequestContext mirrors
// events.LambdaFunctionURLRequestContext type, removing unused fields.
type LambdaFunctionURLRequestContext struct {
RequestID string
APIID string
DomainName string
TimeEpoch int64
HTTP LambdaFunctionURLRequestContextHTTPDescription
}
// LambdaFunctionURLRequestContextHTTPDescription mirrors
// events.LambdaFunctionURLRequestContextHTTPDescription type, removing unused
// fields.
type LambdaFunctionURLRequestContextHTTPDescription struct {
Method string
Path string
Protocol string
SourceIP string
UserAgent string
}