1
      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']},
2
  • What is team? Commented Nov 12, 2021 at 4:22
  • @Marcin, team has the structure: team = [{'id' : 'hekspkh', 'role' : 'admin', 'name' : 'Devin' }, ] Commented Nov 12, 2021 at 19:17

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.