LoginSignup
4
1

More than 5 years have passed since last update.

AWSのDynamoDBに最小のコードでscanでデータを取得する

Last updated at Posted at 2016-08-18

これや

dynamo.go
package main

import (
    "fmt"
    "log"
    "path"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/dynamodb"


    sess := session.New(&aws.Config{Region: aws.String("us-east-1")})

    svc := dynamodb.New(sess)

    params := &dynamodb.ScanInput{
        TableName: aws.String("TABLE_NAME"), // Required
        AttributesToGet: []*string{
            aws.String("TARGET_ COLUMN"), // Required
            // More values...
        },
    }
    resp, err := svc.Scan(params)

    if err != nil {
        // Print the error, cast err to awserr.Error to get the Code and
        // Message from an error.
        fmt.Println(err.Error())
        return
    }

    // Pretty-print the response data.
    fmt.Println(resp)
}
{
  Count: 2,
  Items: [{
      TARGET_COLUMN: {
        S: "foo"
      }
    },{
      TARGET_COLUMN: {
        S: "bar"
      }
    }],
  ScannedCount: 2
}
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1