github.com/Foodji/aws-lambda-go@v1.20.2/events/s3.go (about)

     1  // Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
     2  
     3  package events
     4  
     5  import (
     6  	"encoding/json"
     7  	"net/url"
     8  	"time"
     9  )
    10  
    11  // S3Event which wrap an array of S3EventRecord
    12  type S3Event struct {
    13  	Records []S3EventRecord `json:"Records"`
    14  }
    15  
    16  // S3EventRecord which wrap record data
    17  type S3EventRecord struct {
    18  	EventVersion      string              `json:"eventVersion"`
    19  	EventSource       string              `json:"eventSource"`
    20  	AWSRegion         string              `json:"awsRegion"`
    21  	EventTime         time.Time           `json:"eventTime"`
    22  	EventName         string              `json:"eventName"`
    23  	PrincipalID       S3UserIdentity      `json:"userIdentity"`
    24  	RequestParameters S3RequestParameters `json:"requestParameters"`
    25  	ResponseElements  map[string]string   `json:"responseElements"`
    26  	S3                S3Entity            `json:"s3"`
    27  }
    28  
    29  type S3UserIdentity struct {
    30  	PrincipalID string `json:"principalId"`
    31  }
    32  
    33  type S3RequestParameters struct {
    34  	SourceIPAddress string `json:"sourceIPAddress"`
    35  }
    36  
    37  type S3Entity struct {
    38  	SchemaVersion   string   `json:"s3SchemaVersion"`
    39  	ConfigurationID string   `json:"configurationId"`
    40  	Bucket          S3Bucket `json:"bucket"`
    41  	Object          S3Object `json:"object"`
    42  }
    43  
    44  type S3Bucket struct {
    45  	Name          string         `json:"name"`
    46  	OwnerIdentity S3UserIdentity `json:"ownerIdentity"`
    47  	Arn           string         `json:"arn"`
    48  }
    49  
    50  type S3Object struct {
    51  	Key           string `json:"key"`
    52  	Size          int64  `json:"size,omitempty"`
    53  	URLDecodedKey string `json:"urlDecodedKey"`
    54  	VersionID     string `json:"versionId"`
    55  	ETag          string `json:"eTag"`
    56  	Sequencer     string `json:"sequencer"`
    57  }
    58  
    59  func (o *S3Object) UnmarshalJSON(data []byte) error {
    60  	type rawS3Object S3Object
    61  	if err := json.Unmarshal(data, (*rawS3Object)(o)); err != nil {
    62  		return err
    63  	}
    64  	key, err := url.QueryUnescape(o.Key)
    65  	if err != nil {
    66  		return err
    67  	}
    68  	o.URLDecodedKey = key
    69  
    70  	return nil
    71  }
    72  
    73  type S3TestEvent struct {
    74  	Service   string    `json:"Service"`
    75  	Bucket    string    `json:"Bucket"`
    76  	Event     string    `json:"Event"`
    77  	Time      time.Time `json:"Time"`
    78  	RequestID string    `json:"RequestId"`
    79  	HostID    string    `json:"HostId"`
    80  }