Created
July 23, 2015 23:41
-
-
Save natebrennand/bf5fc06c23ae98f7c7dd to your computer and use it in GitHub Desktop.
debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/awserr" | |
"github.com/aws/aws-sdk-go/aws/awsutil" | |
"github.com/aws/aws-sdk-go/service/dynamodb" | |
) | |
func main() { | |
svc := dynamodb.New(nil) | |
params := &dynamodb.DescribeTableInput{ | |
TableName: aws.String("who-is-who"), // Required | |
} | |
resp, err := svc.DescribeTable(params) | |
if err != nil { | |
if awsErr, ok := err.(awserr.Error); ok { | |
// Generic AWS error with Code, Message, and original error (if any) | |
fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr()) | |
if reqErr, ok := err.(awserr.RequestFailure); ok { | |
// A service error occurred | |
fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID()) | |
} | |
} else { | |
// This case should never be hit, the SDK should always return an | |
// error which satisfies the awserr.Error interface. | |
fmt.Println(err.Error()) | |
} | |
} | |
// Pretty-print the response data. | |
fmt.Println(awsutil.StringValue(resp)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"os" | |
"gopkg.in/underarmour/dynago.v1" | |
) | |
var ( | |
awsKey string | |
awsSecret string | |
dynamoRegion string | |
dynamoEndpoint string | |
) | |
// m is a convenience type for using kayvee. | |
type m map[string]interface{} | |
// requiredEnv tries to find a value in the environment variables. If a value is not | |
// found the program will panaic. | |
func requiredEnv(key string) string { | |
value := os.Getenv(key) | |
if value == "" { | |
log.Fatalf("Missing env key %s", key) | |
} | |
return value | |
} | |
func setupEnvVars() { | |
awsKey = requiredEnv("AWS_ACCESS_KEY_ID") | |
awsSecret = requiredEnv("AWS_SECRET_ACCESS_KEY") | |
dynamoRegion = requiredEnv("DYNAMO_REGION") | |
dynamoEndpoint = requiredEnv("DYNAMO_ENDPOINT") | |
} | |
func main() { | |
setupEnvVars() | |
e := dynago.NewAwsExecutor(dynamoEndpoint, dynamoRegion, awsKey, awsSecret) | |
c := dynago.NewClient(e) | |
resp, err := c.DescribeTable("who-is-who") | |
if err != nil { | |
println(err.Error()) | |
return | |
} | |
println(resp) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment