Skip to content

improv(idempotency): expose record status & expiry config + make DynamoDB Client optional #1679

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

Conversation

dreamorosi
Copy link
Contributor

Description of your changes

As discussed in the linked issue this PR targets three areas of the Idempotency package. All the change aim at improving the DX for customers who decide to bring their own persistence layer, the documentation on how to actually write your own persistence layer will be addressed in a future PR.

DynamoDB Client

The DynamoDBPersistenceLayer relies on two AWS SDK modules: @aws-sdk/client-dynamodb and @aws-sdk/lib-dynamodb.

Before this PR the latter was listed as dependency while the other was only a development dependency. This mean that one was installed automatically upon installing the Idempotency utility while the other was to be installed manually by customers.

This PR marks both modules as devDependencies so that both must be installed explicitly by customers. This not only is in line with all other Powertools utilities, but also allows customers developing their own persistence layers to avoid installing an unnecessary dependency.

A third AWS SDK module (@aws-sdk/util-base64-node) is still listed as regular dependency, this is because the module is used to generate idempotency keys regardless of the persistence store used, so the module is considered as required.

This PR also introduces the concept of peerDependencies (learn more). This allows us to tell npm which versions of these optional dependencies the utility is compatible with. If customers try to install a version outside the range npm will emit a warning and exit the process.

IdempotencyRecordStatus as constant

The IdempotencyRecordStatus object is a map/dictionary of value that facilitate working with the states that an idempotency record can assume throughout its lifecycle:

const IdempotencyRecordStatus = {
  INPROGRESS: 'INPROGRESS',
  COMPLETED: 'COMPLETED',
  EXPIRED: 'EXPIRED',
} as const;

Before this PR the object was included as part of the types folder even though it's not a type. When building custom providers the dictionary must be imported, however doing so from an import like @aws-lambda-powertools/idempotency/types can be confusing.

This PR moves the object to the constants file and exposes it via the default export: @aws-lambda-powertools/idempotency. In doing so, the PR also modifies all the occurrences of imports throughout the package - this has caused the diff to include more files than expected.

getExpiresAfterSeconds() method

expiresAfterSeconds is a private property of the BasePersistenceLayer class. The value is configurable when initializing a new persistence layer and indicates the amount of time a record is kept around for idempotency - this is also known as ttl.

The class uses this value when creating a new IdempotencyRecord, this is fine for persistence stores like DynamoDB that use one of the items attributes as ttl key. Some other stores instead set the property either or both at the time of instantiating a new client or when writing an item.

In order to facilitate the former case, this PR exposes the property via a new getExpiresAfterSeconds() method that can be used by classes that extend the BasePersistenceLayer to get the value before seeing any record.

Related issues, RFCs

Issue number: #1678

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective and works
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@dreamorosi dreamorosi requested a review from a team September 14, 2023 00:07
@dreamorosi dreamorosi self-assigned this Sep 14, 2023
@dreamorosi dreamorosi linked an issue Sep 14, 2023 that may be closed by this pull request
2 tasks
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation idempotency This item relates to the Idempotency Utility dependencies Changes that touch dependencies, e.g. Dependabot, etc. internal PRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.) tests PRs that add or change tests labels Sep 14, 2023
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Sep 14, 2023
@github-actions github-actions bot added the enhancement PRs that introduce minor changes, usually to existing features label Sep 14, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@dreamorosi dreamorosi requested a review from am29d September 14, 2023 09:34
@dreamorosi dreamorosi merged commit cabee4d into main Sep 14, 2023
@dreamorosi dreamorosi deleted the 1678-maintenance-expose-record-status-expiry-config-+-make-dynamodb-deps-optional branch September 14, 2023 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Changes that touch dependencies, e.g. Dependabot, etc. documentation Improvements or additions to documentation enhancement PRs that introduce minor changes, usually to existing features idempotency This item relates to the Idempotency Utility internal PRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.) size/L PRs between 100-499 LOC tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: expose record status & expiry config + make DynamoDB deps optional
2 participants