forked from aws/aws-lambda-go
/
s3.go
80 lines (68 loc) · 2.14 KB
/
s3.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
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
package events
import (
"encoding/json"
"net/url"
"time"
)
// S3Event which wrap an array of S3EventRecord
type S3Event struct {
Records []S3EventRecord `json:"Records"`
}
// S3EventRecord which wrap record data
type S3EventRecord struct {
EventVersion string `json:"eventVersion"`
EventSource string `json:"eventSource"`
AWSRegion string `json:"awsRegion"`
EventTime time.Time `json:"eventTime"`
EventName string `json:"eventName"`
PrincipalID S3UserIdentity `json:"userIdentity"`
RequestParameters S3RequestParameters `json:"requestParameters"`
ResponseElements map[string]string `json:"responseElements"`
S3 S3Entity `json:"s3"`
}
type S3UserIdentity struct {
PrincipalID string `json:"principalId"`
}
type S3RequestParameters struct {
SourceIPAddress string `json:"sourceIPAddress"`
}
type S3Entity struct {
SchemaVersion string `json:"s3SchemaVersion"`
ConfigurationID string `json:"configurationId"`
Bucket S3Bucket `json:"bucket"`
Object S3Object `json:"object"`
}
type S3Bucket struct {
Name string `json:"name"`
OwnerIdentity S3UserIdentity `json:"ownerIdentity"`
Arn string `json:"arn"`
}
type S3Object struct {
Key string `json:"key"`
Size int64 `json:"size,omitempty"`
URLDecodedKey string `json:"urlDecodedKey"`
VersionID string `json:"versionId"`
ETag string `json:"eTag"`
Sequencer string `json:"sequencer"`
}
func (o *S3Object) UnmarshalJSON(data []byte) error {
type rawS3Object S3Object
if err := json.Unmarshal(data, (*rawS3Object)(o)); err != nil {
return err
}
key, err := url.QueryUnescape(o.Key)
if err != nil {
return err
}
o.URLDecodedKey = key
return nil
}
type S3TestEvent struct {
Service string `json:"Service"`
Bucket string `json:"Bucket"`
Event string `json:"Event"`
Time time.Time `json:"Time"`
RequestID string `json:"RequestId"`
HostID string `json:"HostId"`
}