AWS Code Sample

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.


Deletes an item from an Amazon DynamoDB table.

/* Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package main import ( "" "" "" "" "fmt" "os" ) // Item has the values for a movie type Item struct { Year int `json:"year"` Title string `json:"title"` } func main() { // Initialize a session in us-west-2 that the SDK will use to load // credentials from the shared credentials file ~/.aws/credentials. sess, err := session.NewSession(&aws.Config{ Region: aws.String("us-west-2")}, ) // Create DynamoDB client svc := dynamodb.New(sess) item := Item{ Year: 2015, Title: "The Big New Movie", } av, err := dynamodbattribute.MarshalMap(item) if err != nil { fmt.Println("Got error marshalling map:") fmt.Println(err.Error()) os.Exit(1) } input := &dynamodb.DeleteItemInput{ Key: av, TableName: aws.String("Movies"), } _, err = svc.DeleteItem(input) if err != nil { fmt.Println("Got error calling DeleteItem") fmt.Println(err.Error()) return } fmt.Println("Deleted 'The Big New Movie' (2015)") }

Sample Details

Service: dynamodb

Last tested: 2019-03-12

Author: Doug-AWS

Type: full-example

On this page: