Пример #1
0
func TestMain(m *testing.M) {
	db = dynamodb.New(&aws.Config{
		Region:      "mock-region",
		Credentials: aws.DetectCreds("AKID", "SECRET", ""),
		MaxRetries:  2,
	})
	db.Handlers.Send.Clear() // mock sending

	os.Exit(m.Run())
}
Пример #2
0
func TestMakingABasicRequest(t *testing.T) {
	client := dynamodb.New(nil)
	resp, e := client.ListTables(&dynamodb.ListTablesInput{
		Limit: aws.Long(1),
	})
	err := aws.Error(e)
	_, _, _ = resp, e, err // avoid unused warnings

	assert.NoError(t, nil, err)

}
Пример #3
0
func TestErrorHandling(t *testing.T) {
	client := dynamodb.New(nil)
	resp, e := client.DescribeTable(&dynamodb.DescribeTableInput{
		TableName: aws.String("fake-table"),
	})
	err := aws.Error(e)
	_, _, _ = resp, e, err // avoid unused warnings

	assert.NotEqual(t, nil, err)
	assert.Equal(t, "ResourceNotFoundException", err.Code)
	utilassert.Match(t, "Requested resource not found: Table: fake-table not found", err.Message)

}
Пример #4
0
func TestValidateCRC32DoesNotMatchNoComputeChecksum(t *testing.T) {
	svc := dynamodb.New(&aws.Config{
		Region:                  "mock-region",
		Credentials:             aws.DetectCreds("AKID", "SECRET", ""),
		MaxRetries:              2,
		DisableComputeChecksums: true,
	})
	svc.Handlers.Send.Clear() // mock sending

	req := mockCRCResponse(svc, 200, `{"TableNames":["A"]}`, "1234")
	assert.NoError(t, req.Error)

	assert.Equal(t, 0, int(req.RetryCount))

	// CRC check disabled. Does not affect output parsing
	out := req.Data.(*dynamodb.ListTablesOutput)
	assert.Equal(t, "A", *out.TableNames[0])
}
Пример #5
0
func ExampleDynamoDB_DescribeTable() {
	svc := dynamodb.New(nil)

	params := &dynamodb.DescribeTableInput{
		TableName: aws.String("TableName"), // Required
	}
	resp, err := svc.DescribeTable(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Пример #6
0
func ExampleDynamoDB_ListTables() {
	svc := dynamodb.New(nil)

	params := &dynamodb.ListTablesInput{
		ExclusiveStartTableName: aws.String("TableName"),
		Limit: aws.Long(1),
	}
	resp, err := svc.ListTables(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Пример #7
0
func TestCustomRetryRules(t *testing.T) {
	d := dynamodb.New(&aws.Config{MaxRetries: -1})
	assert.Equal(t, d.MaxRetries(), uint(10))
}
Пример #8
0
func ExampleDynamoDB_Scan() {
	svc := dynamodb.New(nil)

	params := &dynamodb.ScanInput{
		TableName: aws.String("TableName"), // Required
		AttributesToGet: []*string{
			aws.String("AttributeName"), // Required
			// More values...
		},
		ConditionalOperator: aws.String("ConditionalOperator"),
		ExclusiveStartKey: &map[string]*dynamodb.AttributeValue{
			"Key": &dynamodb.AttributeValue{ // Required
				B:    []byte("PAYLOAD"),
				BOOL: aws.Boolean(true),
				BS: [][]byte{
					[]byte("PAYLOAD"), // Required
					// More values...
				},
				L: []*dynamodb.AttributeValue{
					&dynamodb.AttributeValue{ // Required
					// Recursive values...
					},
					// More values...
				},
				M: &map[string]*dynamodb.AttributeValue{
					"Key": &dynamodb.AttributeValue{ // Required
					// Recursive values...
					},
					// More values...
				},
				N: aws.String("NumberAttributeValue"),
				NS: []*string{
					aws.String("NumberAttributeValue"), // Required
					// More values...
				},
				NULL: aws.Boolean(true),
				S:    aws.String("StringAttributeValue"),
				SS: []*string{
					aws.String("StringAttributeValue"), // Required
					// More values...
				},
			},
			// More values...
		},
		ExpressionAttributeNames: &map[string]*string{
			"Key": aws.String("AttributeName"), // Required
			// More values...
		},
		ExpressionAttributeValues: &map[string]*dynamodb.AttributeValue{
			"Key": &dynamodb.AttributeValue{ // Required
				B:    []byte("PAYLOAD"),
				BOOL: aws.Boolean(true),
				BS: [][]byte{
					[]byte("PAYLOAD"), // Required
					// More values...
				},
				L: []*dynamodb.AttributeValue{
					&dynamodb.AttributeValue{ // Required
					// Recursive values...
					},
					// More values...
				},
				M: &map[string]*dynamodb.AttributeValue{
					"Key": &dynamodb.AttributeValue{ // Required
					// Recursive values...
					},
					// More values...
				},
				N: aws.String("NumberAttributeValue"),
				NS: []*string{
					aws.String("NumberAttributeValue"), // Required
					// More values...
				},
				NULL: aws.Boolean(true),
				S:    aws.String("StringAttributeValue"),
				SS: []*string{
					aws.String("StringAttributeValue"), // Required
					// More values...
				},
			},
			// More values...
		},
		FilterExpression:       aws.String("ConditionExpression"),
		IndexName:              aws.String("IndexName"),
		Limit:                  aws.Long(1),
		ProjectionExpression:   aws.String("ProjectionExpression"),
		ReturnConsumedCapacity: aws.String("ReturnConsumedCapacity"),
		ScanFilter: &map[string]*dynamodb.Condition{
			"Key": &dynamodb.Condition{ // Required
				ComparisonOperator: aws.String("ComparisonOperator"), // Required
				AttributeValueList: []*dynamodb.AttributeValue{
					&dynamodb.AttributeValue{ // Required
						B:    []byte("PAYLOAD"),
						BOOL: aws.Boolean(true),
						BS: [][]byte{
							[]byte("PAYLOAD"), // Required
							// More values...
						},
						L: []*dynamodb.AttributeValue{
							&dynamodb.AttributeValue{ // Required
							// Recursive values...
							},
							// More values...
						},
						M: &map[string]*dynamodb.AttributeValue{
							"Key": &dynamodb.AttributeValue{ // Required
							// Recursive values...
							},
							// More values...
						},
						N: aws.String("NumberAttributeValue"),
						NS: []*string{
							aws.String("NumberAttributeValue"), // Required
							// More values...
						},
						NULL: aws.Boolean(true),
						S:    aws.String("StringAttributeValue"),
						SS: []*string{
							aws.String("StringAttributeValue"), // Required
							// More values...
						},
					},
					// More values...
				},
			},
			// More values...
		},
		Segment:       aws.Long(1),
		Select:        aws.String("Select"),
		TotalSegments: aws.Long(1),
	}
	resp, err := svc.Scan(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Пример #9
0
func ExampleDynamoDB_BatchWriteItem() {
	svc := dynamodb.New(nil)

	params := &dynamodb.BatchWriteItemInput{
		RequestItems: &map[string][]*dynamodb.WriteRequest{ // Required
			"Key": []*dynamodb.WriteRequest{ // Required
				&dynamodb.WriteRequest{ // Required
					DeleteRequest: &dynamodb.DeleteRequest{
						Key: &map[string]*dynamodb.AttributeValue{ // Required
							"Key": &dynamodb.AttributeValue{ // Required
								B:    []byte("PAYLOAD"),
								BOOL: aws.Boolean(true),
								BS: [][]byte{
									[]byte("PAYLOAD"), // Required
									// More values...
								},
								L: []*dynamodb.AttributeValue{
									&dynamodb.AttributeValue{ // Required
									// Recursive values...
									},
									// More values...
								},
								M: &map[string]*dynamodb.AttributeValue{
									"Key": &dynamodb.AttributeValue{ // Required
									// Recursive values...
									},
									// More values...
								},
								N: aws.String("NumberAttributeValue"),
								NS: []*string{
									aws.String("NumberAttributeValue"), // Required
									// More values...
								},
								NULL: aws.Boolean(true),
								S:    aws.String("StringAttributeValue"),
								SS: []*string{
									aws.String("StringAttributeValue"), // Required
									// More values...
								},
							},
							// More values...
						},
					},
					PutRequest: &dynamodb.PutRequest{
						Item: &map[string]*dynamodb.AttributeValue{ // Required
							"Key": &dynamodb.AttributeValue{ // Required
								B:    []byte("PAYLOAD"),
								BOOL: aws.Boolean(true),
								BS: [][]byte{
									[]byte("PAYLOAD"), // Required
									// More values...
								},
								L: []*dynamodb.AttributeValue{
									&dynamodb.AttributeValue{ // Required
									// Recursive values...
									},
									// More values...
								},
								M: &map[string]*dynamodb.AttributeValue{
									"Key": &dynamodb.AttributeValue{ // Required
									// Recursive values...
									},
									// More values...
								},
								N: aws.String("NumberAttributeValue"),
								NS: []*string{
									aws.String("NumberAttributeValue"), // Required
									// More values...
								},
								NULL: aws.Boolean(true),
								S:    aws.String("StringAttributeValue"),
								SS: []*string{
									aws.String("StringAttributeValue"), // Required
									// More values...
								},
							},
							// More values...
						},
					},
				},
				// More values...
			},
			// More values...
		},
		ReturnConsumedCapacity:      aws.String("ReturnConsumedCapacity"),
		ReturnItemCollectionMetrics: aws.String("ReturnItemCollectionMetrics"),
	}
	resp, err := svc.BatchWriteItem(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Пример #10
0
func ExampleDynamoDB_PutItem() {
	svc := dynamodb.New(nil)

	params := &dynamodb.PutItemInput{
		Item: &map[string]*dynamodb.AttributeValue{ // Required
			"Key": &dynamodb.AttributeValue{ // Required
				B:    []byte("PAYLOAD"),
				BOOL: aws.Boolean(true),
				BS: [][]byte{
					[]byte("PAYLOAD"), // Required
					// More values...
				},
				L: []*dynamodb.AttributeValue{
					&dynamodb.AttributeValue{ // Required
					// Recursive values...
					},
					// More values...
				},
				M: &map[string]*dynamodb.AttributeValue{
					"Key": &dynamodb.AttributeValue{ // Required
					// Recursive values...
					},
					// More values...
				},
				N: aws.String("NumberAttributeValue"),
				NS: []*string{
					aws.String("NumberAttributeValue"), // Required
					// More values...
				},
				NULL: aws.Boolean(true),
				S:    aws.String("StringAttributeValue"),
				SS: []*string{
					aws.String("StringAttributeValue"), // Required
					// More values...
				},
			},
			// More values...
		},
		TableName:           aws.String("TableName"), // Required
		ConditionExpression: aws.String("ConditionExpression"),
		ConditionalOperator: aws.String("ConditionalOperator"),
		Expected: &map[string]*dynamodb.ExpectedAttributeValue{
			"Key": &dynamodb.ExpectedAttributeValue{ // Required
				AttributeValueList: []*dynamodb.AttributeValue{
					&dynamodb.AttributeValue{ // Required
						B:    []byte("PAYLOAD"),
						BOOL: aws.Boolean(true),
						BS: [][]byte{
							[]byte("PAYLOAD"), // Required
							// More values...
						},
						L: []*dynamodb.AttributeValue{
							&dynamodb.AttributeValue{ // Required
							// Recursive values...
							},
							// More values...
						},
						M: &map[string]*dynamodb.AttributeValue{
							"Key": &dynamodb.AttributeValue{ // Required
							// Recursive values...
							},
							// More values...
						},
						N: aws.String("NumberAttributeValue"),
						NS: []*string{
							aws.String("NumberAttributeValue"), // Required
							// More values...
						},
						NULL: aws.Boolean(true),
						S:    aws.String("StringAttributeValue"),
						SS: []*string{
							aws.String("StringAttributeValue"), // Required
							// More values...
						},
					},
					// More values...
				},
				ComparisonOperator: aws.String("ComparisonOperator"),
				Exists:             aws.Boolean(true),
				Value: &dynamodb.AttributeValue{
					B:    []byte("PAYLOAD"),
					BOOL: aws.Boolean(true),
					BS: [][]byte{
						[]byte("PAYLOAD"), // Required
						// More values...
					},
					L: []*dynamodb.AttributeValue{
						&dynamodb.AttributeValue{ // Required
						// Recursive values...
						},
						// More values...
					},
					M: &map[string]*dynamodb.AttributeValue{
						"Key": &dynamodb.AttributeValue{ // Required
						// Recursive values...
						},
						// More values...
					},
					N: aws.String("NumberAttributeValue"),
					NS: []*string{
						aws.String("NumberAttributeValue"), // Required
						// More values...
					},
					NULL: aws.Boolean(true),
					S:    aws.String("StringAttributeValue"),
					SS: []*string{
						aws.String("StringAttributeValue"), // Required
						// More values...
					},
				},
			},
			// More values...
		},
		ExpressionAttributeNames: &map[string]*string{
			"Key": aws.String("AttributeName"), // Required
			// More values...
		},
		ExpressionAttributeValues: &map[string]*dynamodb.AttributeValue{
			"Key": &dynamodb.AttributeValue{ // Required
				B:    []byte("PAYLOAD"),
				BOOL: aws.Boolean(true),
				BS: [][]byte{
					[]byte("PAYLOAD"), // Required
					// More values...
				},
				L: []*dynamodb.AttributeValue{
					&dynamodb.AttributeValue{ // Required
					// Recursive values...
					},
					// More values...
				},
				M: &map[string]*dynamodb.AttributeValue{
					"Key": &dynamodb.AttributeValue{ // Required
					// Recursive values...
					},
					// More values...
				},
				N: aws.String("NumberAttributeValue"),
				NS: []*string{
					aws.String("NumberAttributeValue"), // Required
					// More values...
				},
				NULL: aws.Boolean(true),
				S:    aws.String("StringAttributeValue"),
				SS: []*string{
					aws.String("StringAttributeValue"), // Required
					// More values...
				},
			},
			// More values...
		},
		ReturnConsumedCapacity:      aws.String("ReturnConsumedCapacity"),
		ReturnItemCollectionMetrics: aws.String("ReturnItemCollectionMetrics"),
		ReturnValues:                aws.String("ReturnValue"),
	}
	resp, err := svc.PutItem(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Пример #11
0
func ExampleDynamoDB_GetItem() {
	svc := dynamodb.New(nil)

	params := &dynamodb.GetItemInput{
		Key: &map[string]*dynamodb.AttributeValue{ // Required
			"Key": &dynamodb.AttributeValue{ // Required
				B:    []byte("PAYLOAD"),
				BOOL: aws.Boolean(true),
				BS: [][]byte{
					[]byte("PAYLOAD"), // Required
					// More values...
				},
				L: []*dynamodb.AttributeValue{
					&dynamodb.AttributeValue{ // Required
					// Recursive values...
					},
					// More values...
				},
				M: &map[string]*dynamodb.AttributeValue{
					"Key": &dynamodb.AttributeValue{ // Required
					// Recursive values...
					},
					// More values...
				},
				N: aws.String("NumberAttributeValue"),
				NS: []*string{
					aws.String("NumberAttributeValue"), // Required
					// More values...
				},
				NULL: aws.Boolean(true),
				S:    aws.String("StringAttributeValue"),
				SS: []*string{
					aws.String("StringAttributeValue"), // Required
					// More values...
				},
			},
			// More values...
		},
		TableName: aws.String("TableName"), // Required
		AttributesToGet: []*string{
			aws.String("AttributeName"), // Required
			// More values...
		},
		ConsistentRead: aws.Boolean(true),
		ExpressionAttributeNames: &map[string]*string{
			"Key": aws.String("AttributeName"), // Required
			// More values...
		},
		ProjectionExpression:   aws.String("ProjectionExpression"),
		ReturnConsumedCapacity: aws.String("ReturnConsumedCapacity"),
	}
	resp, err := svc.GetItem(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Пример #12
0
func ExampleDynamoDB_CreateTable() {
	svc := dynamodb.New(nil)

	params := &dynamodb.CreateTableInput{
		AttributeDefinitions: []*dynamodb.AttributeDefinition{ // Required
			&dynamodb.AttributeDefinition{ // Required
				AttributeName: aws.String("KeySchemaAttributeName"), // Required
				AttributeType: aws.String("ScalarAttributeType"),    // Required
			},
			// More values...
		},
		KeySchema: []*dynamodb.KeySchemaElement{ // Required
			&dynamodb.KeySchemaElement{ // Required
				AttributeName: aws.String("KeySchemaAttributeName"), // Required
				KeyType:       aws.String("KeyType"),                // Required
			},
			// More values...
		},
		ProvisionedThroughput: &dynamodb.ProvisionedThroughput{ // Required
			ReadCapacityUnits:  aws.Long(1), // Required
			WriteCapacityUnits: aws.Long(1), // Required
		},
		TableName: aws.String("TableName"), // Required
		GlobalSecondaryIndexes: []*dynamodb.GlobalSecondaryIndex{
			&dynamodb.GlobalSecondaryIndex{ // Required
				IndexName: aws.String("IndexName"), // Required
				KeySchema: []*dynamodb.KeySchemaElement{ // Required
					&dynamodb.KeySchemaElement{ // Required
						AttributeName: aws.String("KeySchemaAttributeName"), // Required
						KeyType:       aws.String("KeyType"),                // Required
					},
					// More values...
				},
				Projection: &dynamodb.Projection{ // Required
					NonKeyAttributes: []*string{
						aws.String("NonKeyAttributeName"), // Required
						// More values...
					},
					ProjectionType: aws.String("ProjectionType"),
				},
				ProvisionedThroughput: &dynamodb.ProvisionedThroughput{ // Required
					ReadCapacityUnits:  aws.Long(1), // Required
					WriteCapacityUnits: aws.Long(1), // Required
				},
			},
			// More values...
		},
		LocalSecondaryIndexes: []*dynamodb.LocalSecondaryIndex{
			&dynamodb.LocalSecondaryIndex{ // Required
				IndexName: aws.String("IndexName"), // Required
				KeySchema: []*dynamodb.KeySchemaElement{ // Required
					&dynamodb.KeySchemaElement{ // Required
						AttributeName: aws.String("KeySchemaAttributeName"), // Required
						KeyType:       aws.String("KeyType"),                // Required
					},
					// More values...
				},
				Projection: &dynamodb.Projection{ // Required
					NonKeyAttributes: []*string{
						aws.String("NonKeyAttributeName"), // Required
						// More values...
					},
					ProjectionType: aws.String("ProjectionType"),
				},
			},
			// More values...
		},
	}
	resp, err := svc.CreateTable(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}