Skip to content

Helper package to easily access some aws-sdk-go's methods (SNS, SQS, DynamoDB, Rekognition, S3) & aws-lambda-go utilities.

License

Notifications You must be signed in to change notification settings

andream16/aws-sdk-go-bindings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-sdk-go-bindings CircleCI GoDoc Go Report Card Apache V2 License

Helper to easily access some aws-sdk-go's methods and lambda utilities like preparing an sns default message and unmarshal an image coming out from a stream like:

// UnmarshalDynamoEvent unmarshals a events.DynamoDBEventRecord into a given target.
// Out has to be a pointer.
func UnmarshalDynamoEvent(event events.DynamoDBEventRecord, out interface{}) error {

	if reflect.DeepEqual(event, reflect.Zero(reflect.TypeOf(event)).Interface()) {
		return errors.Wrap(bindings.ErrInvalidParameter, "event")
	}
	if reflect.ValueOf(out).Kind() != reflect.Ptr {
		return errors.Wrap(bindings.ErrInvalidParameter, "out")
	}

	img := event.Change.NewImage
	if len(img) == 0 {
		return errors.New("event's image is empty")
	}

	m := make(map[string]*dynamodb.AttributeValue, len(img))

	for k, v := range img {

		b, err := v.MarshalJSON()
		if err != nil {
			return errors.Wrap(err, "unable to marshal current element to json")
		}

		var attr dynamodb.AttributeValue

		err = json.Unmarshal(b, &attr)
		if err != nil {
			return errors.Wrap(err, "unable to unmarshal current element to json")
		}

		m[k] = &attr

	}

	return dynamodbattribute.UnmarshalMap(m, out)

}

Contributors

Special thanks to: