Improvements to DynamoDB binding
Ensure context propagation in PutItem and other minor changes
Spin-off from PR adding contexts to input bindings
@@ -20,6 +20,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
+ "github.com/mitchellh/mapstructure"
aws_auth "github.com/dapr/components-contrib/authentication/aws"
"github.com/dapr/components-contrib/bindings"
@@ -81,12 +82,10 @@ func (d *DynamoDB) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bi
return nil, err
}
- input := &dynamodb.PutItemInput{
+ _, err = d.client.PutItemWithContext(ctx, &dynamodb.PutItemInput{
Item: item,
TableName: aws.String(d.table),
- }
-
- _, err = d.client.PutItem(input)
+ })
if err != nil {
return nil, err
}
@@ -95,13 +94,8 @@ func (d *DynamoDB) Invoke(ctx context.Context, req *bindings.InvokeRequest) (*bi
}
func (d *DynamoDB) getDynamoDBMetadata(spec bindings.Metadata) (*dynamoDBMetadata, error) {
- b, err := json.Marshal(spec.Properties)
- if err != nil {
- return nil, err
- }
-
var meta dynamoDBMetadata
- err = json.Unmarshal(b, &meta)
+ err := mapstructure.WeakDecode(spec.Properties, &meta)
if err != nil {
return nil, err
}
