How can I import bulk data from a CSV file into DynamoDB?

后端 未结 14 1854
我在风中等你
我在风中等你 2021-01-31 15:08

I am trying to import a CSV file data into AWS DynamoDB.

Here\'s what my CSV file looks like:

first_name  last_name
sri ram
Rahul   Dravid
JetPay  Underw         


        
14条回答
  •  长情又很酷
    2021-01-31 16:11

    One way of importing/exporting stuff:

    """
    Batch-writes data from a file to a dynamo-db database.
    """
    
    import json
    import boto3
    
    # Get items from DynamoDB table like this:
    # aws dynamodb scan --table-name 
    
    # Create dynamodb client.
    client = boto3.client(
        'dynamodb',
        aws_access_key_id='',
        aws_secret_access_key=''
    )
    
    with open('', 'r') as file:
        data = json.loads(file.read())['Items']
    
        # Execute write-data request for each item.
        for item in data:
            client.put_item(
                TableName='',
                Item=item
            )
    

提交回复
热议问题