boto3 dynamodb put_item() error only accepts keyword arguments

Viewed 4194

I'm using boto3 in a lambda function to write information into a dynamodb table.

I get the error put_item() only accepts keyword arguments.

Searching on the web, i found that this error may mean that I am not matching dynamodb partition key, but it seems to me that I am doing everything correctly.

Can anyone help me find the error? Excuse me but this is my first time using aws.

This is my lambda function

import json, boto3

def updateDynamo(Item):
    dynamodb = boto3.resource('dynamodb', region_name = 'eu-central-1')
    table = dynamodb.Table('userInformations')
    response = table.put_item(Item)
    return response

def lambda_handler(event, context):

    userAttributes = event["request"]["userAttributes"]
    email = userAttributes["email"]
    name = userAttributes["name"]
    Item = {
        "email": email,
        "name" : name
    }

    response = updateDynamo(Item)


    print(email, name)
    
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

This is the test event i'm using:

{
  "version": "string",
  "triggerSource": "string",
  "region": "AWSRegion",
  "userPoolId": "string",
  "userName": "string",
  "callerContext": {
    "awsSdkVersion": "string",
    "clientId": "string"
 },
  "request": {
    "userAttributes": {
      "email": "testemail@gmail.com",
      "name": "test user"
    }
  },
  "response": {}
}

My table has email (all char are lowercase) as partition key.

1 Answers

put_item requires keyword only arguments. This means, that in your case instead of:

response = table.put_item(Item)

there should be

response = table.put_item(Item=Item)
Related