feat(aws): support lambda (#334)
This commit is contained in:
21
vendor/github.com/aws/aws-lambda-go/events/README.md
generated
vendored
Normal file
21
vendor/github.com/aws/aws-lambda-go/events/README.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Overview
|
||||
|
||||
This package provides input types for Lambda functions that process AWS events.
|
||||
|
||||
# Samples
|
||||
|
||||
[API Gateway](README_ApiGatewayEvent.md)
|
||||
|
||||
[Cognito Events](README_Cognito.md)
|
||||
|
||||
[Config Events](README_Config.md)
|
||||
|
||||
[DynamoDB Events](README_DynamoDB.md)
|
||||
|
||||
[Kinesis Events](README_Kinesis.md)
|
||||
|
||||
[Kinesis Firehose Events](README_KinesisFirehose.md)
|
||||
|
||||
[S3 Events](README_S3.md)
|
||||
|
||||
[SNS Events](README_SNS.md)
|
||||
36
vendor/github.com/aws/aws-lambda-go/events/README_ApiGatewayEvent.md
generated
vendored
Normal file
36
vendor/github.com/aws/aws-lambda-go/events/README_ApiGatewayEvent.md
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# Overview
|
||||
|
||||
API Gateway events consist of a request that was routed to a Lambda function by API Gateway. When this happens, API Gateway expects the result of the function to be the response that API Gateway should respond with.
|
||||
|
||||
# Sample Function
|
||||
|
||||
The following is a sample class and Lambda function that receives Amazon API Gateway event record data as an input, writes some of the record data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
|
||||
|
||||
```go
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-lambda-go/events"
|
||||
"github.com/aws/aws-lambda-go/lambda"
|
||||
)
|
||||
|
||||
func handleRequest(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
|
||||
fmt.Printf("Processing request data for request %s.\n", request.RequestContext.RequestID)
|
||||
fmt.Printf("Body size = %d.\n", len(request.Body))
|
||||
|
||||
fmt.Println("Headers:")
|
||||
for key, value := range request.Headers {
|
||||
fmt.Printf(" %s: %s\n", key, value)
|
||||
}
|
||||
|
||||
return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
lambda.Start(handleRequest)
|
||||
}
|
||||
```
|
||||
22
vendor/github.com/aws/aws-lambda-go/events/README_Cognito.md
generated
vendored
Normal file
22
vendor/github.com/aws/aws-lambda-go/events/README_Cognito.md
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
# Sample Function
|
||||
|
||||
The following is a sample Lambda function that receives Amazon Cognito event record data as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
|
||||
|
||||
```go
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"github.com/aws/aws-lambda-go/events"
|
||||
)
|
||||
|
||||
func handleRequest(ctx context.Context, cognitoEvent events.CognitoEvent) {
|
||||
for datasetName, datasetRecord := range cognitoEvent.DatasetRecords {
|
||||
fmt.Printf("[%s -- %s] %s -> %s -> %s \n",
|
||||
cognitoEvent.EventType,
|
||||
datasetName,
|
||||
datasetRecord.OldValue,
|
||||
datasetRecord.Op,
|
||||
datasetRecord.NewValue)
|
||||
}
|
||||
}
|
||||
```
|
||||
18
vendor/github.com/aws/aws-lambda-go/events/README_Config.md
generated
vendored
Normal file
18
vendor/github.com/aws/aws-lambda-go/events/README_Config.md
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# Sample Function
|
||||
|
||||
The following is a sample Lambda function that receives Amazon Config event record data as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
|
||||
|
||||
```go
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"github.com/aws/aws-lambda-go/events"
|
||||
)
|
||||
|
||||
func handleRequest(ctx context.Context, configEvent events.ConfigEvent) {
|
||||
fmt.Printf("AWS Config rule: %s\n", configEvent.ConfigRuleName)
|
||||
fmt.Printf("Invoking event JSON: %s\n", configEvent.InvokingEvent)
|
||||
fmt.Printf("Event version: %s\n", configEvent.Version)
|
||||
}
|
||||
|
||||
```
|
||||
79
vendor/github.com/aws/aws-lambda-go/events/README_DynamoDB.md
generated
vendored
Normal file
79
vendor/github.com/aws/aws-lambda-go/events/README_DynamoDB.md
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
# Sample Function
|
||||
|
||||
The following is a sample Lambda function that receives DynamoDB event data as input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs.)
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-lambda-go/events"
|
||||
)
|
||||
|
||||
func handleRequest(ctx context.Context, e events.DynamoDBEvent) {
|
||||
|
||||
for _, record := range e.Records {
|
||||
fmt.Printf("Processing request data for event ID %s, type %s.\n", record.EventID, record.EventName)
|
||||
|
||||
// Print new values for attributes of type String
|
||||
for name, value := range record.Change.NewImage {
|
||||
if value.DataType() == events.DataTypeString {
|
||||
fmt.Printf("Attribute name: %s, value: %s\n", name, value.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
# Reading attribute values
|
||||
|
||||
Stream notifications are delivered to the Lambda handler whenever data in the DynamoDB table is modified.
|
||||
Depending on the Stream settings, a StreamRecord may contain the following data:
|
||||
|
||||
* Keys: key attributes of the modified item.
|
||||
* NewImage: the entire item, as it appears after it was modified.
|
||||
* OldImage: the entire item, as it appeared before it was modified.
|
||||
|
||||
The values for the attributes can be accessed using the AttributeValue type. For each type
|
||||
supported natively by DynamoDB, there is a corresponding accessor method:
|
||||
|
||||
DynamoDB type | AttributeValue accessor method | Return type | DataType constant
|
||||
---------------|--------------------------------|---------------------------|------------------
|
||||
B (Binary) | Binary() | []byte | DataTypeBinary
|
||||
BOOL (Boolean) | Boolean() | bool | DataTypeBoolean
|
||||
BS (Binary Set)| BinarySet() | [][]byte | DataTypeBinarySet
|
||||
L (List) | List() | []AttributeValue | DataTypeList
|
||||
M (Map) | Map() | map[string]AttributeValue | DataTypeMap
|
||||
N (Number) | Number() / Integer() / Float() | string / int64 / float64 | DataTypeNumber
|
||||
NS (Number Set)| NumberSet() | []string | DataTypeNumberSet
|
||||
NULL (Null) | IsNull() | bool | DataTypeNull
|
||||
S (String) | String() | string | DataTypeString
|
||||
SS (String Set)| StringSet() | []string | DataTypeStringSet
|
||||
|
||||
Calling the accessor method for the incorrect type will result in a panic. If the type needs to
|
||||
be discovered in runtime, the method DataType() can be used in order to determine the correct accessor.
|
||||
|
||||
More information about DynamoDB data types can be seen [in this documentation](http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html).
|
||||
|
||||
The following example reads values of attributes name and age, for which types are known to be String and Number:
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-lambda-go/events"
|
||||
)
|
||||
|
||||
func handleRequest(ctx context.Context, e events.DynamoDBEvent) {
|
||||
|
||||
for _, record := range e.Records {
|
||||
fmt.Printf("Processing request data for event ID %s, type %s.\n", record.EventID, record.EventName)
|
||||
|
||||
// Print new values for attributes name and age
|
||||
name := record.Change.NewImage["name"].String()
|
||||
age, _ := record.Change.NewImage["age"].Integer()
|
||||
|
||||
fmt.Printf("Name: %s, age: %d\n", name, age)
|
||||
}
|
||||
}
|
||||
```
|
||||
21
vendor/github.com/aws/aws-lambda-go/events/README_Kinesis.md
generated
vendored
Normal file
21
vendor/github.com/aws/aws-lambda-go/events/README_Kinesis.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Sample Function
|
||||
|
||||
The following is a sample class and Lambda function that receives Amazon Kinesis event record data as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
|
||||
|
||||
```go
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"github.com/aws/aws-lambda-go/events")
|
||||
|
||||
func handler(ctx context.Context, kinesisEvent events.KinesisEvent) {
|
||||
for _, record := range kinesisEvent.Records {
|
||||
kinesisRecord := record.Kinesis
|
||||
dataBytes := kinesisRecordData.Data
|
||||
dataText := string(dataBytes)
|
||||
|
||||
fmt.Printf("%s Data = %s \n", record.EventName, dataText)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
36
vendor/github.com/aws/aws-lambda-go/events/README_KinesisFirehose.md
generated
vendored
Normal file
36
vendor/github.com/aws/aws-lambda-go/events/README_KinesisFirehose.md
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# Sample Function
|
||||
|
||||
The following is a sample Lambda function that transforms Kinesis Firehose records by doing a ToUpper on the data.
|
||||
|
||||
```go
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"github.com/aws/aws-lambda-go/events"
|
||||
)
|
||||
|
||||
func handleRequest(evnt events.KinesisFirehoseEvent) events.KinesisFirehoseResponse {
|
||||
|
||||
fmt.Printf("InvocationId: %s\n", evnt.InvocationId)
|
||||
fmt.Printf("DeliveryStreamArn: %s\n", evnt.DeliveryStreamArn)
|
||||
fmt.Printf("Region: %s\n", evnt.Region)
|
||||
|
||||
var response events.KinesisFirehoseResponse
|
||||
|
||||
for _, record := range evnt.Records {
|
||||
fmt.Printf("RecordId: %s\n", record.RecordId)
|
||||
fmt.Printf("ApproximateArrivalTimestamp: %s\n", record.ApproximateArrivalTimestamp)
|
||||
|
||||
// Transform data: ToUpper the data
|
||||
var transformedRecord kinesisfhevents.FirehoseResponseRecord
|
||||
transformedRecord.RecordId = record.RecordId
|
||||
transformedRecord.Result = kinesisfhevents.TransformedStateOk
|
||||
transformedRecord.Data = strings.ToUpper(string(record.Data))
|
||||
|
||||
response.Records = append(response.Records, transformedRecord)
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
```
|
||||
18
vendor/github.com/aws/aws-lambda-go/events/README_S3.md
generated
vendored
Normal file
18
vendor/github.com/aws/aws-lambda-go/events/README_S3.md
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# Sample Function
|
||||
|
||||
The following is a sample class and Lambda function that receives Amazon S3 event record data as an input and writes some of the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
|
||||
|
||||
```go
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"github.com/aws/aws-lambda-go/events")
|
||||
|
||||
func handler(ctx context.Context, s3Event events.S3Event) {
|
||||
for _, record := range s3Event.Records {
|
||||
s3 := record.S3
|
||||
fmt.Printf("[%s - %s] Bucket = %s, Key = %s \n", record.EventSource, record.EventTime, s3.Bucket.Name, s3.Object.Key)
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
21
vendor/github.com/aws/aws-lambda-go/events/README_SNS.md
generated
vendored
Normal file
21
vendor/github.com/aws/aws-lambda-go/events/README_SNS.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
# Sample Function
|
||||
|
||||
The following is a sample class and Lambda function that receives Amazon SNS event record data as input, writes some of the record data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that by default anything written to Console will be logged as CloudWatch Logs events.)
|
||||
|
||||
```go
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-lambda-go/events"
|
||||
)
|
||||
|
||||
func handler(ctx context.Context, snsEvent events.SNSEvent) {
|
||||
for _, record := range snsEvent.Records {
|
||||
snsRecord := record.SNS
|
||||
|
||||
fmt.Printf("[%s %s] Message = %s \n", record.EventSource, snsRecord.Timestamp, snsRecord.Message)
|
||||
}
|
||||
}
|
||||
```
|
||||
63
vendor/github.com/aws/aws-lambda-go/events/apigw.go
generated
vendored
Normal file
63
vendor/github.com/aws/aws-lambda-go/events/apigw.go
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
package events
|
||||
|
||||
// APIGatewayProxyRequest contains data coming from the API Gateway proxy
|
||||
type APIGatewayProxyRequest struct {
|
||||
Resource string `json:"resource"` // The resource path defined in API Gateway
|
||||
Path string `json:"path"` // The url path for the caller
|
||||
HTTPMethod string `json:"httpMethod"`
|
||||
Headers map[string]string `json:"headers"`
|
||||
QueryStringParameters map[string]string `json:"queryStringParameters"`
|
||||
PathParameters map[string]string `json:"pathParameters"`
|
||||
StageVariables map[string]string `json:"stageVariables"`
|
||||
RequestContext APIGatewayProxyRequestContext `json:"requestContext"`
|
||||
Body string `json:"body"`
|
||||
IsBase64Encoded bool `json:"isBase64Encoded,omitempty"`
|
||||
}
|
||||
|
||||
// APIGatewayProxyResponse configures the response to be returned by API Gateway for the request
|
||||
type APIGatewayProxyResponse struct {
|
||||
StatusCode int `json:"statusCode"`
|
||||
Headers map[string]string `json:"headers"`
|
||||
Body string `json:"body"`
|
||||
IsBase64Encoded bool `json:"isBase64Encoded,omitempty"`
|
||||
}
|
||||
|
||||
// APIGatewayProxyRequestContext contains the information to identify the AWS account and resources invoking the
|
||||
// Lambda function. It also includes Cognito identity information for the caller.
|
||||
type APIGatewayProxyRequestContext struct {
|
||||
AccountID string `json:"accountId"`
|
||||
ResourceID string `json:"resourceId"`
|
||||
Stage string `json:"stage"`
|
||||
RequestID string `json:"requestId"`
|
||||
Identity APIGatewayRequestIdentity `json:"identity"`
|
||||
ResourcePath string `json:"resourcePath"`
|
||||
Authorizer map[string]interface{} `json:"authorizer"`
|
||||
HTTPMethod string `json:"httpMethod"`
|
||||
APIID string `json:"apiId"` // The API Gateway rest API Id
|
||||
}
|
||||
|
||||
// APIGatewayRequestIdentity contains identity information for the request caller.
|
||||
type APIGatewayRequestIdentity struct {
|
||||
CognitoIdentityPoolID string `json:"cognitoIdentityPoolId"`
|
||||
AccountID string `json:"accountId"`
|
||||
CognitoIdentityID string `json:"cognitoIdentityId"`
|
||||
Caller string `json:"caller"`
|
||||
APIKey string `json:"apiKey"`
|
||||
SourceIP string `json:"sourceIp"`
|
||||
CognitoAuthenticationType string `json:"cognitoAuthenticationType"`
|
||||
CognitoAuthenticationProvider string `json:"cognitoAuthenticationProvider"`
|
||||
UserArn string `json:"userArn"`
|
||||
UserAgent string `json:"userAgent"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
// APIGatewayCustomAuthorizerContext represents the expected format of an API Gateway custom authorizer response.
|
||||
// Deprecated. Code should be updated to use the Authorizer map from APIGatewayRequestIdentity. Ex: Authorizer["principalId"]
|
||||
type APIGatewayCustomAuthorizerContext struct {
|
||||
PrincipalID *string `json:"principalId"`
|
||||
StringKey *string `json:"stringKey,omitempty"`
|
||||
NumKey *int `json:"numKey,omitempty"`
|
||||
BoolKey *bool `json:"boolKey,omitempty"`
|
||||
}
|
||||
457
vendor/github.com/aws/aws-lambda-go/events/attributevalue.go
generated
vendored
Normal file
457
vendor/github.com/aws/aws-lambda-go/events/attributevalue.go
generated
vendored
Normal file
@@ -0,0 +1,457 @@
|
||||
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// DynamoDBAttributeValue provides convenient access for a value stored in DynamoDB.
|
||||
// For more information, please see http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_AttributeValue.html
|
||||
type DynamoDBAttributeValue struct {
|
||||
value anyValue
|
||||
dataType DynamoDBDataType
|
||||
}
|
||||
|
||||
// Binary provides access to an attribute of type Binary.
|
||||
// Method panics if the attribute is not of type Binary.
|
||||
func (av DynamoDBAttributeValue) Binary() []byte {
|
||||
av.ensureType(DataTypeBinary)
|
||||
return av.value.([]byte)
|
||||
}
|
||||
|
||||
// Boolean provides access to an attribute of type Boolean.
|
||||
// Method panics if the attribute is not of type Boolean.
|
||||
func (av DynamoDBAttributeValue) Boolean() bool {
|
||||
av.ensureType(DataTypeBoolean)
|
||||
return av.value.(bool)
|
||||
}
|
||||
|
||||
// BinarySet provides access to an attribute of type Binary Set.
|
||||
// Method panics if the attribute is not of type BinarySet.
|
||||
func (av DynamoDBAttributeValue) BinarySet() [][]byte {
|
||||
av.ensureType(DataTypeBinarySet)
|
||||
return av.value.([][]byte)
|
||||
}
|
||||
|
||||
// List provides access to an attribute of type List. Each element
|
||||
// of the list is an DynamoDBAttributeValue itself.
|
||||
// Method panics if the attribute is not of type List.
|
||||
func (av DynamoDBAttributeValue) List() []DynamoDBAttributeValue {
|
||||
av.ensureType(DataTypeList)
|
||||
return av.value.([]DynamoDBAttributeValue)
|
||||
}
|
||||
|
||||
// Map provides access to an attribute of type Map. They Keys are strings
|
||||
// and the values are DynamoDBAttributeValue instances.
|
||||
// Method panics if the attribute is not of type Map.
|
||||
func (av DynamoDBAttributeValue) Map() map[string]DynamoDBAttributeValue {
|
||||
av.ensureType(DataTypeMap)
|
||||
return av.value.(map[string]DynamoDBAttributeValue)
|
||||
}
|
||||
|
||||
// Number provides access to an attribute of type Number.
|
||||
// DynamoDB sends the values as strings. For convenience please see also
|
||||
// the methods Integer() and Float().
|
||||
// Method panics if the attribute is not of type Number.
|
||||
func (av DynamoDBAttributeValue) Number() string {
|
||||
av.ensureType(DataTypeNumber)
|
||||
return av.value.(string)
|
||||
}
|
||||
|
||||
// Integer provides access to an attribute of type Number.
|
||||
// DynamoDB sends the values as strings. For convenience this method
|
||||
// provides conversion to int. If the value cannot be represented by
|
||||
// a signed integer, err.Err = ErrRange and the returned value is the maximum magnitude integer
|
||||
// of an int64 of the appropriate sign.
|
||||
// Method panics if the attribute is not of type Number.
|
||||
func (av DynamoDBAttributeValue) Integer() (int64, error) {
|
||||
s, err := strconv.ParseFloat(av.Number(), 64)
|
||||
return int64(s), err
|
||||
}
|
||||
|
||||
// Float provides access to an attribute of type Number.
|
||||
// DynamoDB sends the values as strings. For convenience this method
|
||||
// provides conversion to float64.
|
||||
// The returned value is the nearest floating point number rounded using IEEE754 unbiased rounding.
|
||||
// If the number is more than 1/2 ULP away from the largest floating point number of the given size,
|
||||
// the value returned is ±Inf, err.Err = ErrRange.
|
||||
// Method panics if the attribute is not of type Number.
|
||||
func (av DynamoDBAttributeValue) Float() (float64, error) {
|
||||
s, err := strconv.ParseFloat(av.Number(), 64)
|
||||
return s, err
|
||||
}
|
||||
|
||||
// NumberSet provides access to an attribute of type Number Set.
|
||||
// DynamoDB sends the numbers as strings.
|
||||
// Method panics if the attribute is not of type Number.
|
||||
func (av DynamoDBAttributeValue) NumberSet() []string {
|
||||
av.ensureType(DataTypeNumberSet)
|
||||
return av.value.([]string)
|
||||
}
|
||||
|
||||
// String provides access to an attribute of type String.
|
||||
// Method panics if the attribute is not of type String.
|
||||
func (av DynamoDBAttributeValue) String() string {
|
||||
av.ensureType(DataTypeString)
|
||||
return av.value.(string)
|
||||
}
|
||||
|
||||
// StringSet provides access to an attribute of type String Set.
|
||||
// Method panics if the attribute is not of type String Set.
|
||||
func (av DynamoDBAttributeValue) StringSet() []string {
|
||||
av.ensureType(DataTypeStringSet)
|
||||
return av.value.([]string)
|
||||
}
|
||||
|
||||
// IsNull returns true if the attribute is of type Null.
|
||||
func (av DynamoDBAttributeValue) IsNull() bool {
|
||||
return av.value == nil
|
||||
}
|
||||
|
||||
// DataType provides access to the DynamoDB type of the attribute
|
||||
func (av DynamoDBAttributeValue) DataType() DynamoDBDataType {
|
||||
return av.dataType
|
||||
}
|
||||
|
||||
// NewStringAttribute creates an DynamoDBAttributeValue containing a String
|
||||
func NewStringAttribute(value string) DynamoDBAttributeValue {
|
||||
var av DynamoDBAttributeValue
|
||||
av.value = value
|
||||
av.dataType = DataTypeString
|
||||
return av
|
||||
}
|
||||
|
||||
// DynamoDBDataType specifies the type supported natively by DynamoDB for an attribute
|
||||
type DynamoDBDataType int
|
||||
|
||||
const (
|
||||
DataTypeBinary DynamoDBDataType = iota
|
||||
DataTypeBoolean
|
||||
DataTypeBinarySet
|
||||
DataTypeList
|
||||
DataTypeMap
|
||||
DataTypeNumber
|
||||
DataTypeNumberSet
|
||||
DataTypeNull
|
||||
DataTypeString
|
||||
DataTypeStringSet
|
||||
)
|
||||
|
||||
type anyValue interface{}
|
||||
|
||||
// UnsupportedDynamoDBTypeError is the error returned when trying to unmarshal a DynamoDB Attribute type not recognized by this library
|
||||
type UnsupportedDynamoDBTypeError struct {
|
||||
Type string
|
||||
}
|
||||
|
||||
func (e UnsupportedDynamoDBTypeError) Error() string {
|
||||
return fmt.Sprintf("unsupported DynamoDB attribute type, %v", e.Type)
|
||||
}
|
||||
|
||||
// IncompatibleDynamoDBTypeError is the error passed in a panic when calling an accessor for an incompatible type
|
||||
type IncompatibleDynamoDBTypeError struct {
|
||||
Requested DynamoDBDataType
|
||||
Actual DynamoDBDataType
|
||||
}
|
||||
|
||||
func (e IncompatibleDynamoDBTypeError) Error() string {
|
||||
return fmt.Sprintf("accessor called for incompatible type, requested type %v but actual type was %v", e.Requested, e.Actual)
|
||||
}
|
||||
|
||||
func (av *DynamoDBAttributeValue) ensureType(expectedType DynamoDBDataType) {
|
||||
if av.dataType != expectedType {
|
||||
panic(IncompatibleDynamoDBTypeError{Requested: expectedType, Actual: av.dataType})
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalJSON implements custom marshaling to be used by the standard json/encoding package
|
||||
func (av DynamoDBAttributeValue) MarshalJSON() ([]byte, error) {
|
||||
|
||||
var buff bytes.Buffer
|
||||
var err error
|
||||
var b []byte
|
||||
|
||||
switch av.dataType {
|
||||
case DataTypeBinary:
|
||||
buff.WriteString(`{ "B":`)
|
||||
b, err = json.Marshal(av.value.([]byte))
|
||||
buff.Write(b)
|
||||
|
||||
case DataTypeBoolean:
|
||||
buff.WriteString(`{ "BOOL":`)
|
||||
b, err = json.Marshal(av.value.(bool))
|
||||
buff.Write(b)
|
||||
|
||||
case DataTypeBinarySet:
|
||||
buff.WriteString(`{ "BS":`)
|
||||
b, err = json.Marshal(av.value.([][]byte))
|
||||
buff.Write(b)
|
||||
|
||||
case DataTypeList:
|
||||
buff.WriteString(`{ "L":`)
|
||||
b, err = json.Marshal(av.value.([]DynamoDBAttributeValue))
|
||||
buff.Write(b)
|
||||
|
||||
case DataTypeMap:
|
||||
buff.WriteString(`{ "M":`)
|
||||
b, err = json.Marshal(av.value.(map[string]DynamoDBAttributeValue))
|
||||
buff.Write(b)
|
||||
|
||||
case DataTypeNumber:
|
||||
buff.WriteString(`{ "N":`)
|
||||
b, err = json.Marshal(av.value.(string))
|
||||
buff.Write(b)
|
||||
|
||||
case DataTypeNumberSet:
|
||||
buff.WriteString(`{ "NS":`)
|
||||
b, err = json.Marshal(av.value.([]string))
|
||||
buff.Write(b)
|
||||
|
||||
case DataTypeNull:
|
||||
buff.WriteString(`{ "NULL": true `)
|
||||
|
||||
case DataTypeString:
|
||||
buff.WriteString(`{ "S":`)
|
||||
b, err = json.Marshal(av.value.(string))
|
||||
buff.Write(b)
|
||||
|
||||
case DataTypeStringSet:
|
||||
buff.WriteString(`{ "SS":`)
|
||||
b, err = json.Marshal(av.value.([]string))
|
||||
buff.Write(b)
|
||||
}
|
||||
|
||||
buff.WriteString(`}`)
|
||||
return buff.Bytes(), err
|
||||
}
|
||||
|
||||
func unmarshalNull(target *DynamoDBAttributeValue) error {
|
||||
target.value = nil
|
||||
target.dataType = DataTypeNull
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalString(target *DynamoDBAttributeValue, value interface{}) error {
|
||||
var ok bool
|
||||
target.value, ok = value.(string)
|
||||
target.dataType = DataTypeString
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: S type should contain a string")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalBinary(target *DynamoDBAttributeValue, value interface{}) error {
|
||||
stringValue, ok := value.(string)
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: B type should contain a base64 string")
|
||||
}
|
||||
|
||||
binaryValue, err := base64.StdEncoding.DecodeString(stringValue)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
target.value = binaryValue
|
||||
target.dataType = DataTypeBinary
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalBoolean(target *DynamoDBAttributeValue, value interface{}) error {
|
||||
booleanValue, ok := value.(bool)
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: BOOL type should contain a boolean")
|
||||
}
|
||||
|
||||
target.value = booleanValue
|
||||
target.dataType = DataTypeBoolean
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalBinarySet(target *DynamoDBAttributeValue, value interface{}) error {
|
||||
list, ok := value.([]interface{})
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: BS type should contain a list of base64 strings")
|
||||
}
|
||||
|
||||
binarySet := make([][]byte, len(list))
|
||||
|
||||
for index, element := range list {
|
||||
var err error
|
||||
elementString := element.(string)
|
||||
binarySet[index], err = base64.StdEncoding.DecodeString(elementString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
target.value = binarySet
|
||||
target.dataType = DataTypeBinarySet
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalList(target *DynamoDBAttributeValue, value interface{}) error {
|
||||
list, ok := value.([]interface{})
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: L type should contain a list")
|
||||
}
|
||||
|
||||
DynamoDBAttributeValues := make([]DynamoDBAttributeValue, len(list))
|
||||
for index, element := range list {
|
||||
|
||||
elementMap, ok := element.(map[string]interface{})
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: element of a list is not an DynamoDBAttributeValue")
|
||||
}
|
||||
|
||||
var elementDynamoDBAttributeValue DynamoDBAttributeValue
|
||||
err := unmarshalDynamoDBAttributeValueMap(&elementDynamoDBAttributeValue, elementMap)
|
||||
if err != nil {
|
||||
return errors.New("DynamoDBAttributeValue: unmarshal of child DynamoDBAttributeValue failed")
|
||||
}
|
||||
DynamoDBAttributeValues[index] = elementDynamoDBAttributeValue
|
||||
}
|
||||
target.value = DynamoDBAttributeValues
|
||||
target.dataType = DataTypeList
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalMap(target *DynamoDBAttributeValue, value interface{}) error {
|
||||
m, ok := value.(map[string]interface{})
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: M type should contain a map")
|
||||
}
|
||||
|
||||
DynamoDBAttributeValues := make(map[string]DynamoDBAttributeValue)
|
||||
for k, v := range m {
|
||||
|
||||
elementMap, ok := v.(map[string]interface{})
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: element of a map is not an DynamoDBAttributeValue")
|
||||
}
|
||||
|
||||
var elementDynamoDBAttributeValue DynamoDBAttributeValue
|
||||
err := unmarshalDynamoDBAttributeValueMap(&elementDynamoDBAttributeValue, elementMap)
|
||||
if err != nil {
|
||||
return errors.New("DynamoDBAttributeValue: unmarshal of child DynamoDBAttributeValue failed")
|
||||
}
|
||||
DynamoDBAttributeValues[k] = elementDynamoDBAttributeValue
|
||||
}
|
||||
target.value = DynamoDBAttributeValues
|
||||
target.dataType = DataTypeMap
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalNumber(target *DynamoDBAttributeValue, value interface{}) error {
|
||||
var ok bool
|
||||
target.value, ok = value.(string)
|
||||
target.dataType = DataTypeNumber
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: N type should contain a string")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalNumberSet(target *DynamoDBAttributeValue, value interface{}) error {
|
||||
list, ok := value.([]interface{})
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: NS type should contain a list of strings")
|
||||
}
|
||||
|
||||
numberSet := make([]string, len(list))
|
||||
|
||||
for index, element := range list {
|
||||
numberSet[index], ok = element.(string)
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: NS type should contain a list of strings")
|
||||
}
|
||||
}
|
||||
|
||||
target.value = numberSet
|
||||
target.dataType = DataTypeNumberSet
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalStringSet(target *DynamoDBAttributeValue, value interface{}) error {
|
||||
list, ok := value.([]interface{})
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: SS type should contain a list of strings")
|
||||
}
|
||||
|
||||
stringSet := make([]string, len(list))
|
||||
|
||||
for index, element := range list {
|
||||
stringSet[index], ok = element.(string)
|
||||
if !ok {
|
||||
return errors.New("DynamoDBAttributeValue: SS type should contain a list of strings")
|
||||
}
|
||||
}
|
||||
|
||||
target.value = stringSet
|
||||
target.dataType = DataTypeStringSet
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalDynamoDBAttributeValue(target *DynamoDBAttributeValue, typeLabel string, jsonValue interface{}) error {
|
||||
|
||||
switch typeLabel {
|
||||
case "NULL":
|
||||
return unmarshalNull(target)
|
||||
case "B":
|
||||
return unmarshalBinary(target, jsonValue)
|
||||
case "BOOL":
|
||||
return unmarshalBoolean(target, jsonValue)
|
||||
case "BS":
|
||||
return unmarshalBinarySet(target, jsonValue)
|
||||
case "L":
|
||||
return unmarshalList(target, jsonValue)
|
||||
case "M":
|
||||
return unmarshalMap(target, jsonValue)
|
||||
case "N":
|
||||
return unmarshalNumber(target, jsonValue)
|
||||
case "NS":
|
||||
return unmarshalNumberSet(target, jsonValue)
|
||||
case "S":
|
||||
return unmarshalString(target, jsonValue)
|
||||
case "SS":
|
||||
return unmarshalStringSet(target, jsonValue)
|
||||
default:
|
||||
target.value = nil
|
||||
target.dataType = DataTypeNull
|
||||
return UnsupportedDynamoDBTypeError{typeLabel}
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals a JSON description of this DynamoDBAttributeValue
|
||||
func (av *DynamoDBAttributeValue) UnmarshalJSON(b []byte) error {
|
||||
var m map[string]interface{}
|
||||
|
||||
err := json.Unmarshal(b, &m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return unmarshalDynamoDBAttributeValueMap(av, m)
|
||||
}
|
||||
|
||||
func unmarshalDynamoDBAttributeValueMap(target *DynamoDBAttributeValue, m map[string]interface{}) error {
|
||||
if m == nil {
|
||||
return errors.New("DynamoDBAttributeValue: does not contain a map")
|
||||
}
|
||||
|
||||
if len(m) != 1 {
|
||||
return errors.New("DynamoDBAttributeValue: map must contain a single type")
|
||||
}
|
||||
|
||||
for k, v := range m {
|
||||
return unmarshalDynamoDBAttributeValue(target, k, v)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
55
vendor/github.com/aws/aws-lambda-go/events/cloudwatch_logs.go
generated
vendored
Normal file
55
vendor/github.com/aws/aws-lambda-go/events/cloudwatch_logs.go
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// CloudwatchLogsEvent represents raw data from a cloudwatch logs event
|
||||
type CloudwatchLogsEvent struct {
|
||||
AWSLogs CloudwatchLogsRawData `json:"awslogs"`
|
||||
}
|
||||
|
||||
// CloudwatchLogsRawData contains gzipped base64 json representing the bulk
|
||||
// of a cloudwatch logs event
|
||||
type CloudwatchLogsRawData struct {
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
// Parse returns a slice of structs represting 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
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
buf.ReadFrom(zr)
|
||||
|
||||
err = json.Unmarshal(buf.Bytes(), &d)
|
||||
return
|
||||
}
|
||||
|
||||
// CloudwatchLogsData is an unmarshal'd, ungzip'd, cloudwatch logs event
|
||||
type CloudwatchLogsData struct {
|
||||
Owner string `json:"owner"`
|
||||
LogGroup string `json:"logGroup"`
|
||||
LogStream string `json:"logStream"`
|
||||
SubscriptionFilters []string `json:"subscriptionFilters"`
|
||||
MessageType string `json:"messageType"`
|
||||
LogEvents []CloudwatchLogsLogEvent `json:"logEvents"`
|
||||
}
|
||||
|
||||
// LogEvent represents a log entry from cloudwatch logs
|
||||
type CloudwatchLogsLogEvent struct {
|
||||
ID string `json:"id"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
21
vendor/github.com/aws/aws-lambda-go/events/cognito.go
generated
vendored
Normal file
21
vendor/github.com/aws/aws-lambda-go/events/cognito.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
package events
|
||||
|
||||
// CognitoEvent contains data from an event sent from AWS Cognito
|
||||
type CognitoEvent struct {
|
||||
DatasetName string `json:"datasetName"`
|
||||
DatasetRecords map[string]CognitoDatasetRecord `json:"datasetRecords"`
|
||||
EventType string `json:"eventType"`
|
||||
IdentityID string `json:"identityId"`
|
||||
IdentityPoolID string `json:"identityPoolId"`
|
||||
Region string `json:"region"`
|
||||
Version int `json:"version"`
|
||||
}
|
||||
|
||||
// CognitoDatasetRecord represents a record from an AWS Cognito event
|
||||
type CognitoDatasetRecord struct {
|
||||
NewValue string `json:"newValue"`
|
||||
OldValue string `json:"oldValue"`
|
||||
Op string `json:"op"`
|
||||
}
|
||||
17
vendor/github.com/aws/aws-lambda-go/events/config.go
generated
vendored
Normal file
17
vendor/github.com/aws/aws-lambda-go/events/config.go
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
package events
|
||||
|
||||
// ConfigEvent contains data from an event sent from AWS Config
|
||||
type ConfigEvent struct {
|
||||
AccountID string `json:"accountId"` // The ID of the AWS account that owns the rule
|
||||
ConfigRuleArn string `json:"configRuleArn"` // The ARN that AWS Config assigned to the rule
|
||||
ConfigRuleID string `json:"configRuleId"`
|
||||
ConfigRuleName string `json:"configRuleName"` // The name that you assigned to the rule that caused AWS Config to publish the event
|
||||
EventLeftScope bool `json:"eventLeftScope"` // A boolean value that indicates whether the AWS resource to be evaluated has been removed from the rule's scope
|
||||
ExecutionRoleArn string `json:"executionRoleArn"`
|
||||
InvokingEvent string `json:"invokingEvent"` // If the event is published in response to a resource configuration change, this value contains a JSON configuration item
|
||||
ResultToken string `json:"resultToken"` // A token that the function must pass to AWS Config with the PutEvaluations call
|
||||
RuleParameters string `json:"ruleParameters"` // Key/value pairs that the function processes as part of its evaluation logic
|
||||
Version string `json:"version"`
|
||||
}
|
||||
117
vendor/github.com/aws/aws-lambda-go/events/dynamodb.go
generated
vendored
Normal file
117
vendor/github.com/aws/aws-lambda-go/events/dynamodb.go
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
package events
|
||||
|
||||
// The DynamoDBEvent stream event handled to Lambda
|
||||
// http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-ddb-update
|
||||
type DynamoDBEvent struct {
|
||||
Records []DynamoDBEventRecord `json:"Records"`
|
||||
}
|
||||
|
||||
// DynamoDbEventRecord stores information about each record of a DynamoDb stream event
|
||||
type DynamoDBEventRecord struct {
|
||||
// The region in which the GetRecords request was received.
|
||||
AWSRegion string `json:"awsRegion"`
|
||||
|
||||
// The main body of the stream record, containing all of the DynamoDB-specific
|
||||
// fields.
|
||||
Change DynamoDBStreamRecord `json:"dynamodb"`
|
||||
|
||||
// A globally unique identifier for the event that was recorded in this stream
|
||||
// record.
|
||||
EventID string `json:"eventID"`
|
||||
|
||||
// The type of data modification that was performed on the DynamoDB table:
|
||||
//
|
||||
// * INSERT - a new item was added to the table.
|
||||
//
|
||||
// * MODIFY - one or more of an existing item's attributes were modified.
|
||||
//
|
||||
// * REMOVE - the item was deleted from the table
|
||||
EventName string `json:"eventName"`
|
||||
|
||||
// The AWS service from which the stream record originated. For DynamoDB Streams,
|
||||
// this is aws:dynamodb.
|
||||
EventSource string `json:"eventSource"`
|
||||
|
||||
// The version number of the stream record format. This number is updated whenever
|
||||
// the structure of Record is modified.
|
||||
//
|
||||
// Client applications must not assume that eventVersion will remain at a particular
|
||||
// value, as this number is subject to change at any time. In general, eventVersion
|
||||
// will only increase as the low-level DynamoDB Streams API evolves.
|
||||
EventVersion string `json:"eventVersion"`
|
||||
|
||||
// The event source ARN of DynamoDB
|
||||
EventSourceArn string `json:"eventSourceARN"`
|
||||
}
|
||||
|
||||
// A description of a single data modification that was performed on an item
|
||||
// in a DynamoDB table.
|
||||
type DynamoDBStreamRecord struct {
|
||||
|
||||
// The approximate date and time when the stream record was created, in UNIX
|
||||
// epoch time (http://www.epochconverter.com/) format.
|
||||
ApproximateCreationDateTime SecondsEpochTime `json:"ApproximateCreationDateTime,omitempty"`
|
||||
|
||||
// The primary key attribute(s) for the DynamoDB item that was modified.
|
||||
Keys map[string]DynamoDBAttributeValue `json:"Keys,omitempty"`
|
||||
|
||||
// The item in the DynamoDB table as it appeared after it was modified.
|
||||
NewImage map[string]DynamoDBAttributeValue `json:"NewImage,omitempty"`
|
||||
|
||||
// The item in the DynamoDB table as it appeared before it was modified.
|
||||
OldImage map[string]DynamoDBAttributeValue `json:"OldImage,omitempty"`
|
||||
|
||||
// The sequence number of the stream record.
|
||||
SequenceNumber string `json:"SequenceNumber"`
|
||||
|
||||
// The size of the stream record, in bytes.
|
||||
SizeBytes int64 `json:"SizeBytes"`
|
||||
|
||||
// The type of data from the modified DynamoDB item that was captured in this
|
||||
// stream record.
|
||||
StreamViewType string `json:"StreamViewType"`
|
||||
}
|
||||
|
||||
type DynamoDBKeyType string
|
||||
|
||||
const (
|
||||
DynamoDBKeyTypeHash DynamoDBKeyType = "HASH"
|
||||
DynamoDBKeyTypeRange DynamoDBKeyType = "RANGE"
|
||||
)
|
||||
|
||||
type DynamoDBOperationType string
|
||||
|
||||
const (
|
||||
DynamoDBOperationTypeInsert DynamoDBOperationType = "INSERT"
|
||||
DynamoDBOperationTypeModify DynamoDBOperationType = "MODIFY"
|
||||
DynamoDBOperationTypeRemove DynamoDBOperationType = "REMOVE"
|
||||
)
|
||||
|
||||
type DynamoDBSharedIteratorType string
|
||||
|
||||
const (
|
||||
DynamoDBShardIteratorTypeTrimHorizon DynamoDBSharedIteratorType = "TRIM_HORIZON"
|
||||
DynamoDBShardIteratorTypeLatest DynamoDBSharedIteratorType = "LATEST"
|
||||
DynamoDBShardIteratorTypeAtSequenceNumber DynamoDBSharedIteratorType = "AT_SEQUENCE_NUMBER"
|
||||
DynamoDBShardIteratorTypeAfterSequenceNumber DynamoDBSharedIteratorType = "AFTER_SEQUENCE_NUMBER"
|
||||
)
|
||||
|
||||
type DynamoDBStreamStatus string
|
||||
|
||||
const (
|
||||
DynamoDBStreamStatusEnabling DynamoDBStreamStatus = "ENABLING"
|
||||
DynamoDBStreamStatusEnabled DynamoDBStreamStatus = "ENABLED"
|
||||
DynamoDBStreamStatusDisabling DynamoDBStreamStatus = "DISABLING"
|
||||
DynamoDBStreamStatusDisabled DynamoDBStreamStatus = "DISABLED"
|
||||
)
|
||||
|
||||
type DynamoDBStreamViewType string
|
||||
|
||||
const (
|
||||
DynamoDBStreamViewTypeNewImage DynamoDBStreamViewType = "NEW_IMAGE" // the entire item, as it appeared after it was modified.
|
||||
DynamoDBStreamViewTypeOldImage DynamoDBStreamViewType = "OLD_IMAGE" // the entire item, as it appeared before it was modified.
|
||||
DynamoDBStreamViewTypeNewAndOldImages DynamoDBStreamViewType = "NEW_AND_OLD_IMAGES" // both the new and the old item images of the item.
|
||||
DynamoDBStreamViewTypeKeysOnly DynamoDBStreamViewType = "KEYS_ONLY" // only the key attributes of the modified item.
|
||||
)
|
||||
59
vendor/github.com/aws/aws-lambda-go/events/epoch_time.go
generated
vendored
Normal file
59
vendor/github.com/aws/aws-lambda-go/events/epoch_time.go
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SecondsEpochTime serializes a time.Time in JSON as a UNIX epoch time in seconds
|
||||
type SecondsEpochTime struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
// MilliSecondsEpochTime serializes a time.Time in JSON as a UNIX epoch time in milliseconds.
|
||||
type MilliSecondsEpochTime struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
const secondsToNanoSecondsFactor = 1000000000
|
||||
const milliSecondsToNanoSecondsFactor = 1000000
|
||||
|
||||
func (e SecondsEpochTime) MarshalJSON() ([]byte, error) {
|
||||
// UnixNano() returns the epoch in nanoseconds
|
||||
unixTime := float64(e.UnixNano()) / float64(secondsToNanoSecondsFactor)
|
||||
return json.Marshal(unixTime)
|
||||
}
|
||||
|
||||
func (e *SecondsEpochTime) UnmarshalJSON(b []byte) error {
|
||||
var epoch float64
|
||||
err := json.Unmarshal(b, &epoch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
epochSec := int64(epoch)
|
||||
epochNano := int64((epoch - float64(epochSec)) * float64(secondsToNanoSecondsFactor))
|
||||
|
||||
// time.Unix(sec, nsec) expects the epoch integral seconds in the first parameter
|
||||
// and remaining nanoseconds in the second parameter
|
||||
*e = SecondsEpochTime{time.Unix(epochSec, epochNano)}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e MilliSecondsEpochTime) MarshalJSON() ([]byte, error) {
|
||||
// UnixNano() returns the epoch in nanoseconds
|
||||
unixTimeMs := e.UnixNano() / milliSecondsToNanoSecondsFactor
|
||||
return json.Marshal(unixTimeMs)
|
||||
}
|
||||
|
||||
func (e *MilliSecondsEpochTime) UnmarshalJSON(b []byte) error {
|
||||
var epoch int64
|
||||
err := json.Unmarshal(b, &epoch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*e = MilliSecondsEpochTime{time.Unix(epoch/1000, (epoch%1000)*1000000)}
|
||||
return nil
|
||||
}
|
||||
34
vendor/github.com/aws/aws-lambda-go/events/firehose.go
generated
vendored
Normal file
34
vendor/github.com/aws/aws-lambda-go/events/firehose.go
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
package events
|
||||
|
||||
// KinesisFirehoseEvent represents the input event from Amazon Kinesis Firehose. It is used as the input parameter.
|
||||
type KinesisFirehoseEvent struct {
|
||||
InvocationID string `json:"invocationId"`
|
||||
DeliveryStreamArn string `json:"deliveryStreamArn"`
|
||||
Region string `json:"region"`
|
||||
Records []KinesisFirehoseEventRecord `json:"records"`
|
||||
}
|
||||
|
||||
type KinesisFirehoseEventRecord struct {
|
||||
RecordID string `json:"recordId"`
|
||||
ApproximateArrivalTimestamp MilliSecondsEpochTime `json:"approximateArrivalTimestamp"`
|
||||
Data []byte `json:"data"`
|
||||
}
|
||||
|
||||
// Constants used for describing the transformation result
|
||||
const (
|
||||
KinesisFirehoseTransformedStateOk = "TRANSFORMED_STATE_OK"
|
||||
KinesisFirehoseTransformedStateDropped = "TRANSFORMED_STATE_DROPPED"
|
||||
KinesisFirehoseTransformedStateProcessingFailed = "TRANSFORMED_STATE_PROCESSINGFAILED"
|
||||
)
|
||||
|
||||
type KinesisFirehoseResponse struct {
|
||||
Records []KinesisFirehoseResponseRecord `json:"records"`
|
||||
}
|
||||
|
||||
type KinesisFirehoseResponseRecord struct {
|
||||
RecordID string `json:"recordId"`
|
||||
Result string `json:"result"` // The status of the transformation. May be TransformedStateOk, TransformedStateDropped or TransformedStateProcessingFailed
|
||||
Data []byte `json:"data"`
|
||||
}
|
||||
27
vendor/github.com/aws/aws-lambda-go/events/kinesis.go
generated
vendored
Normal file
27
vendor/github.com/aws/aws-lambda-go/events/kinesis.go
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
package events
|
||||
|
||||
type KinesisEvent struct {
|
||||
Records []KinesisEventRecord `json:"Records"`
|
||||
}
|
||||
|
||||
type KinesisEventRecord struct {
|
||||
AwsRegion string `json:"awsRegion"`
|
||||
EventID string `json:"eventID"`
|
||||
EventName string `json:"eventName"`
|
||||
EventSource string `json:"eventSource"`
|
||||
EventSourceArn string `json:"eventSourceARN"`
|
||||
EventVersion string `json:"eventVersion"`
|
||||
InvokeIdentityArn string `json:"invokeIdentityArn"`
|
||||
Kinesis KinesisRecord `json:"kinesis"`
|
||||
}
|
||||
|
||||
type KinesisRecord struct {
|
||||
ApproximateArrivalTimestamp SecondsEpochTime `json:"approximateArrivalTimestamp"`
|
||||
Data []byte `json:"data"`
|
||||
EncryptionType string `json:"encryptionType,omitempty"`
|
||||
PartitionKey string `json:"partitionKey"`
|
||||
SequenceNumber string `json:"sequenceNumber"`
|
||||
KinesisSchemaVersion string `json:"kinesisSchemaVersion"`
|
||||
}
|
||||
53
vendor/github.com/aws/aws-lambda-go/events/s3.go
generated
vendored
Normal file
53
vendor/github.com/aws/aws-lambda-go/events/s3.go
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type S3Event struct {
|
||||
Records []S3EventRecord `json:"Records"`
|
||||
}
|
||||
|
||||
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"`
|
||||
URLDecodedKey string `json:"urlDecodedKey"`
|
||||
VersionID string `json:"versionId"`
|
||||
ETag string `json:"eTag"`
|
||||
Sequencer string `json:"sequencer"`
|
||||
}
|
||||
32
vendor/github.com/aws/aws-lambda-go/events/sns.go
generated
vendored
Normal file
32
vendor/github.com/aws/aws-lambda-go/events/sns.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
package events
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type SNSEvent struct {
|
||||
Records []SNSEventRecord `json:"Records"`
|
||||
}
|
||||
|
||||
type SNSEventRecord struct {
|
||||
EventVersion string `json:"EventVersion"`
|
||||
EventSubscriptionArn string `json:"EventSubscriptionArn"`
|
||||
EventSource string `json:"EventSource"`
|
||||
SNS SNSEntity `json:"Sns"`
|
||||
}
|
||||
|
||||
type SNSEntity struct {
|
||||
Signature string `json:"Signature"`
|
||||
MessageID string `json:"MessageId"`
|
||||
Type string `json:"Type"`
|
||||
TopicArn string `json:"TopicArn"`
|
||||
MessageAttributes map[string]interface{} `json:"MessageAttributes"`
|
||||
SignatureVersion string `json:"SignatureVersion"`
|
||||
Timestamp time.Time `json:"Timestamp"`
|
||||
SigningCertURL string `json:"SigningCertUrl"`
|
||||
Message string `json:"Message"`
|
||||
UnsubscribeURL string `json:"UnsubscribeUrl"`
|
||||
Subject string `json:"Subject"`
|
||||
}
|
||||
Reference in New Issue
Block a user