"""Update feed_name for Amazon.""" import copy import json import boto3 from boto3.dynamodb.conditions import Key TABLE_NAME = 'prod_feed_ingestion_status' FEED_NAME_OLD = 'Amazon Instant Video Daily' FEED_NAME_NEW = 'amazon_instant_video_daily' def main(): """Run main.""" dynamodb = boto3.resource('dynamodb', region_name='us-east-1') table = dynamodb.Table(TABLE_NAME) filter_expression = Key('feed_name').eq(FEED_NAME_OLD) response = table.query( KeyConditionExpression=filter_expression ) count = 0 for item in response['Items']: print(json.dumps(item, indent=4)) item_updated = copy.deepcopy(item) item_updated['feed_name'] = FEED_NAME_NEW key = { 'feed_name': item['feed_name'], 'date': item['date'] } # table.delete_item(Key=key) table.put_item(Item=item_updated) count += 1 print('Updated items: %s' % count) if __name__ == '__main__': main()