Giter Club home page Giter Club logo

aws's Introduction

aws

common abstractions for interacting with AWS in Go

DynamoDB

The dynamodb package provides an Iterator to easily iterate over the results of a PartiQL query.

sess := session.Must(session.NewSession())
client := dynamodb.New(sess)
query := `SELECT * FROM "people" WHERE "Name" = 'Ryan'`
iter := dynamodb.NewIter(client, query)
for iter.Next(ctx) {
	var p Person
	if err := iter.Document(&p); err != nil {
		return err
	}
    //do stuff with p
}
if iter.Err() != nil {
	return iter.Err()
}

Scan is a helper function for an Iterator that scans a table

scanner := dynamodb.Scan(client, "people")
for scanner.Next(ctx) {
	var p Person
	if err := scanner.Document(&p); err != nil {
		return err
	}
    //do stuff with p
}
if scanner.Err() != nil {
	return scanner.Err()
}

S3

The s3 package provides a Bucket abstraction to allow for easy reading and writing to a bucket.

The NewWriter method returns an io.WriteCloser. The writer MUST be closed for the upload to complete.

sess := session.Must(session.NewSession())
client := s3.New(sess)
bucket := s3.NewBucket(client, "people-bucket")

w := bucket.NewWriter(ctx, "key/to/person.json")
p := newPerson()
if err := json.NewEncoder(w).Encode(&p); err != nil {
    return err
}
// remember to close w
if err := w.Close(); err {
    return err
}

Likewise, The NewReader method returns an io.ReadCloser. The reader must always be closed as well.

r, err := bucket.NewReader(ctx, "key/to/person.json")
if err != nil {
	return err
}
var p Person
if err := json.NewDecoder(r).Decode(&p); err != nil {
	return err
}
// remember to close r
if err := r.Close(); err {
	return err
}

aws's People

Contributors

ryanmiville avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.