Reputation: 4524
I am trying to use the following code, but I am unable to get it to work. It keeps giving me an error message about the filter expression being the incorrect type, even though I am doing exactly what is done in the documentation. What can I do to fix this?
def EndpointDeleted(event):
endpoint = event['Attributes']['EndpointArn']
if('EndpointArn' in event['Attributes']):
client = boto3.client('dynamodb')
response = client.scan(
TableName='sniffergps-mobilehub-812282467-Users',
Select='ALL_ATTRIBUTES',
FilterExpression=Attr('Endpoints').contains(endpoint)
)
return response
But I get an error saying that the filter expression is the incorrect type. I have the following import messages:
import boto3
from boto3.dynamodb.conditions import Key
from boto3.dynamodb.conditions import Attr
Error message:
{
"errorMessage": "Parameter validation failed:\nInvalid type for parameter FilterExpression, value: <boto3.dynamodb.conditions.Contains object at 0x7fdca25e0b38>, type: <class 'boto3.dynamodb.conditions.Contains'>, valid types: <class 'str'>",
"errorType": "ParamValidationError",
"stackTrace": [
[
"/var/task/lambda_function.py",
13,
"lambda_handler",
"return EndpointDeleted(event)"
],
[
"/var/task/lambda_function.py",
24,
"EndpointDeleted",
"FilterExpression=Attr('Endpoints').contains(endpoint)"
],
[
"/var/runtime/botocore/client.py",
312,
"_api_call",
"return self._make_api_call(operation_name, kwargs)"
],
[
"/var/runtime/botocore/client.py",
575,
"_make_api_call",
"api_params, operation_model, context=request_context)"
],
[
"/var/runtime/botocore/client.py",
630,
"_convert_to_request_dict",
"api_params, operation_model)"
],
[
"/var/runtime/botocore/validate.py",
291,
"serialize_to_request",
"raise ParamValidationError(report=report.generate_report())"
]
]
}
Upvotes: 3
Views: 13100
Reputation: 200486
Note the difference in syntax between the Boto3 DynamoDB Client, and the Table Resource.
The FilterExpression
parameter for DynamoDB client expects a string.
The method you are using to set the FilterExpression
parameter looks like the way you would use a DynamoDB.Table resource.
Upvotes: 22