-
Notifications
You must be signed in to change notification settings - Fork 860
/
Copy pathDynamoDBDeleteItem.go
49 lines (39 loc) · 1.09 KB
/
DynamoDBDeleteItem.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
// snippet-start:[dynamodb.go.delete_item.imports]
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"fmt"
"log"
)
// snippet-end:[dynamodb.go.delete_item.imports]
func main() {
// and region from the shared configuration file ~/.aws/config.
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
// Create DynamoDB client
svc := dynamodb.New(sess)
// snippet-start:[dynamodb.go.delete_item.call]
tableName := "Movies"
movieName := "The Big New Movie"
movieYear := "2015"
input := &dynamodb.DeleteItemInput{
Key: map[string]*dynamodb.AttributeValue{
"Year": {
N: aws.String(movieYear),
},
"Title": {
S: aws.String(movieName),
},
},
TableName: aws.String(tableName),
}
_, err := svc.DeleteItem(input)
if err != nil {
log.Fatalf("Got error calling DeleteItem: %s", err)
}
fmt.Println("Deleted '" + movieName + "' (" + movieYear + ") from table " + tableName)
// snippet-end:[dynamodb.go.delete_item.call]
}