1

I am writing a simple dynamodb table scan with a filter expression using the boto3 documentation https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Table.scan

I am getting this error: { "errorMessage": "An error occurred (ValidationException) when calling the Scan operation: ExpressionAttributeNames can only be specified when using expressions", "errorType": "ClientError", Code: import boto3 import pprint from pprint import pprint from boto3.dynamodb.conditions import Key from boto3.dynamodb.conditions import Attr

    dbresource =boto3.resource('dynamodb')

    def lambda_handler(event, context):

    tableobject = dbresource.Table('basicSongsTable')

    response = tableobject.scan(ExpressionAttributeNames={'artist': ':variableartist'},
                            ExpressionAttributeValues={':variableartist': {'S': 'Matt'}})

    pprint(response)

1 Answer 1

3

I'm guessing you want to Scan the table and return when the artist=Matt?

dbresource =boto3.resource('dynamodb')

    def lambda_handler(event, context):

    tableobject = dbresource.Table('basicSongsTable')

    response = tableobject.scan(
    ExpressionAttributeNames={'#a': 'artist'},
    ExpressionAttributeValues={':v': {'S': 'Matt'}},
    FilterExpression='#a=:v'
    )

    print(response)

More examples here: https://github.com/aws-samples/aws-dynamodb-examples/tree/master/DynamoDB-SDK-Examples/python/WorkingWithScans

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

3 Comments

Thank You so much. I don't know why they made it so complex. we need 3 parameter to scan a table. Greatly appreciate Your response
I clicked on that Ok arrow. Isn't that accepted ? Let me know if I need to click on something else
I looked at Your github samples. Great resource. I hope You teach on Udemy

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.