Skip to content

Commit 74651d5

Browse files
committed
add batch write item
1 parent f7f73fc commit 74651d5

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ Compile the pod by running `go build`, then:
1919
{"AmazingTable" {:Keys [{:some-property {:S "SomeValue"}
2020
:something-else {:S "SomethingSomething"}}]}}})
2121

22+
(d/batch-write-item {:RequestItems
23+
{"AmazingTable" [{:PutRequest {:Item {:some-property {:S "abxdggje"}
24+
:something-else {:S "zxcmbnj"}
25+
:another-thing {:S "asdasdsa"}}}}]}})
26+
2227
(d/get-item {:Key {:lalala {:S "zzzzzzzz"}
2328
:bbbbbb {:S "abxbxbxx"}}
2429
:TableName "SomeTable"})

dynamo.go

+17
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ func BatchGetItem(inputMessage *Message) (*dynamodb.BatchGetItemOutput, error) {
2323
return res, err
2424
}
2525

26+
func BatchWriteItem(inputMessage *Message) (*dynamodb.BatchWriteItemOutput, error) {
27+
28+
svc := dynamodb.New(session.New())
29+
input := &dynamodb.BatchWriteItemInput{}
30+
inputList := []dynamodb.BatchWriteItemInput{}
31+
err := json.Unmarshal([]byte(inputMessage.Args), &inputList)
32+
if err != nil {
33+
return nil, err
34+
}
35+
if len(inputList) > 0 {
36+
input = &inputList[0]
37+
}
38+
39+
res, err := svc.BatchWriteItem(input)
40+
return res, err
41+
}
42+
2643
func DescribeTable(inputMessage *Message) (*dynamodb.DescribeTableOutput, error) {
2744

2845
svc := dynamodb.New(session.New())

main.go

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func main() {
2222
{Name: "pod.dynamodb",
2323
Vars: []Var{
2424
{Name: "batch-get-item"},
25+
{Name: "batch-write-item"},
2526
{Name: "describe-table"},
2627
{Name: "get-item"},
2728
{Name: "list-tables"},
@@ -41,6 +42,13 @@ func main() {
4142
} else {
4243
WriteInvokeResponse(message, res)
4344
}
45+
case "pod.dynamodb/batch-write-item":
46+
res, err := BatchWriteItem(message)
47+
if err != nil {
48+
WriteErrorResponse(message, err)
49+
} else {
50+
WriteInvokeResponse(message, res)
51+
}
4452
case "pod.dynamodb/describe-table":
4553
res, err := DescribeTable(message)
4654
if err != nil {

0 commit comments

Comments
 (0)