0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

boto3でDynamoDBテーブルの属性(attribute)を削除する

Last updated at Posted at 2021-05-11

ググってもすぐ見つからなくて難儀したのでここに残します。

remove_attribute.py
import boto3

dynamodb = boto3.resource('dynamodb')

my_table =  dynamodb.Table('MyTable')

partition_key = 'hoge'
sort_key = 123

# 項目の取得
result = my_table.get_item(
    Key= {
        'pk': partition_key,
        'sk': sort_key
    }
)
print(result['Item'])

# 項目から属性の削除
my_table.update_item(
    Key= {
        'pk': partition_key,
        'sk': sort_key
    },
    UpdateExpression='remove foo'
)

# 項目の再取得
result = my_table.get_item(
    Key= {
        'pk': partition_key,
        'sk': sort_key
    }
)
print(result['Item'])
$ python remove_attribute.py
{'pk': 'hoge', 'sk': Decimal('123'), 'foo': 'bar'}
{'pk': 'hoge', 'sk': Decimal('123')}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?