Home > Blockchain >  Inserting List of Maps in AWS DyanmoDB using Boto3 (python 3)
Inserting List of Maps in AWS DyanmoDB using Boto3 (python 3)

Time:11-13

      teamMembers = []
      for member in team:
        teamMembers.append({'M' : {        
          'id' : {'S' : member['id']},
          'role' : {'S' : member['role']},
          'name' : {'S' : member['name']}
        }})      
    
      project = {
        'id' : {
          'S' : data['project']['id']
        },
        'name' : {
          'S' : data['project']['name']
        },
        'team' : {
          'L' : teamMembers
        }
      }

      client.put_item(
        TableName = 'projects',
        Item      = project
      )

This code gives me the following error:

    [ERROR] TypeError: string indices must be integers
Traceback (most recent call last):
  File "/var/task/lambda_function.py", line 36, in lambda_handler
    'id' : {'S' : member['id']},

CodePudding user response:

The error msg indicates that your team is not fully what it is. It seems that it is a list of both dicts and strings, something as the following:

: team = [
   {'id' : 'hekspkh', 'role' : 'admin', 'name' : 'Devin' }, 
   {'id' : 'hekspkh2', 'role' : 'admin2', 'name' : 'Devin2' }, 
   'some_string',
   {'id' : 'hekspkh3', 'role' : 'admin3', 'name' : 'Devin3' }
]

Thus you have to double check your team and filter out those strings which break your code.

  • Related