Skip to content

DynamoDBPersistenceLayer should use ExpressionAttributeNames in _put_record #693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Tankanow opened this issue Sep 23, 2021 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@Tankanow
Copy link
Contributor

Tankanow commented Sep 23, 2021

What were you trying to accomplish?

Expected Behavior

I should be able to use DynamoDB reserved words as Item attributes. For example, ttl is a common DynamoDB Item Time to Live attribute name. A consumer should be able to specify reserved word attribute names for any of the *_attr values when configuring DynamoDBPersistenceLayer.

Current Behavior

_put_record currently throws an exception b/c it uses Python string interpolation instead of ExpressionAttributeNames.

Possible Solution

Switch to ExpressionAttributeNames, e.g.

            self.table.put_item(
                Item=item,
                ConditionExpression='attribute_not_exists(#key) OR #now < :now',
                ExpressionAttributeNames={"#key": self.key_attr, "#now": self.expiry_attr},
                ExpressionAttributeValues={":now": int(now.timestamp())},
            )

Steps to Reproduce (for bugs)

  1. Create a DynamoDB table with a Time to Live attribute called ttl.
  2. Configure a DynamoDBPersistenceLayer with expiry_attr='ttl'
  3. Run

Environment

  • Powertools version used: 1.20.2
  • Packaging format (Layers, PyPi): PyPi
  • AWS Lambda function runtime: Python 3.8
  • Debugging logs

How to enable debug mode**

# paste logs here
@Tankanow Tankanow added bug Something isn't working triage Pending triage from maintainers labels Sep 23, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Sep 23, 2021

Thanks for opening your first issue here! We'll come back to you as soon as we can.

@Tankanow
Copy link
Contributor Author

I'm happy to submit a PR for this. I have it locally.

@heitorlessa
Copy link
Contributor

Hey @Tankanow, same as the other one -- another oversight from our part, I'd love a PR as it's a quick one.

@heitorlessa heitorlessa added area/idempotency pending-release Fix or implementation already in dev waiting to be released and removed triage Pending triage from maintainers labels Sep 25, 2021
@heitorlessa
Copy link
Contributor

This is now available as part of today's release 1.21.0 @Tankanow ;) Thank you so much for contributing that!

https://github.com/awslabs/aws-lambda-powertools-python/releases/tag/v1.21.0

@heitorlessa heitorlessa removed the pending-release Fix or implementation already in dev waiting to be released label Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants