Skip to content
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

feat(idempotency): add custom JMESPath functions #2364

Merged
merged 13 commits into from Apr 16, 2024

Conversation

dreamorosi
Copy link
Contributor

Description of your changes

This PR introduces support for custom JMESPath functions to the Idempotency utility, addressing one of our most requested features (the 5th to be precise).

With this new feature customers can use the powertools_json(), powertools_base64(), and powertools_base64_gzip() custom functions to deserialize encoded payloads and use the values within them as idempotency key.

This is especially useful when working with API Gateway or SQS messages among others, since oftentimes the customer defined part of the payload is encoded as JSON stringified object or base64 encoded value:

import { makeIdempotent, IdempotencyConfig } from '@aws-lambda-powertools/idempotency';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
import type { Context, APIGatewayProxyEvent } from 'aws-lambda';

const persistenceStore = new DynamoDBPersistenceLayer({
  tableName: 'idempotencyTableName',
});

const myHandler = async (
  event: APIGatewayProxyEvent,
  _context: Context
): Promise<void> => {
  // your code goes here here
};

export const handler = makeIdempotent(myHandler, {
  persistenceStore,
  config: new IdempotencyConfig({
    eventKeyJmespath: 'powertools_json(body).["user", "productId"]',
  }),
});

The feature is added by having the Idempotency utility take a dependency on the newly released @aws-lambda-powertools/jmespath package and replacing the existing, and more limited, jmespath module.

The PR also adds the new @aws-lambda-powertools/jmespath utility to the Lambda Layer replacing the existing jmespath dependency.

Related issues, RFCs

Issue number: #1298

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 self-assigned this Apr 15, 2024
@dreamorosi dreamorosi requested review from a team as code owners April 15, 2024 13:32
@dreamorosi dreamorosi linked an issue Apr 15, 2024 that may be closed by this pull request
2 tasks
@boring-cyborg boring-cyborg bot added automation This item relates to automation documentation Improvements or additions to documentation idempotency This item relates to the Idempotency Utility layers Items related to the Lambda Layers pipeline 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 Apr 15, 2024
@pull-request-size pull-request-size bot added the size/M PR between 30-99 LOC label Apr 15, 2024
@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Apr 15, 2024
@dreamorosi dreamorosi marked this pull request as draft April 15, 2024 13:41
@dreamorosi
Copy link
Contributor Author

Converting back to draft to fix an error appearing in the examples app.

@dreamorosi
Copy link
Contributor Author

@dreamorosi dreamorosi marked this pull request as ready for review April 16, 2024 07:55
Copy link
Contributor

@am29d am29d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good, just minor comment on instantiation of PowertoolsFunction()

packages/idempotency/src/IdempotencyHandler.ts Outdated Show resolved Hide resolved
@dreamorosi dreamorosi requested a review from am29d April 16, 2024 12:44
@pull-request-size pull-request-size bot added size/L PRs between 100-499 LOC and removed size/M PR between 30-99 LOC labels Apr 16, 2024
Copy link

sonarcloud bot commented Apr 16, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@am29d am29d merged commit 9721e7c into main Apr 16, 2024
13 checks passed
@am29d am29d deleted the feat/idempotency_custom_jmespath branch April 16, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation This item relates to automation dependencies Changes that touch dependencies, e.g. Dependabot, etc. documentation Improvements or additions to documentation feature PRs that introduce new features or minor changes idempotency This item relates to the Idempotency Utility internal PRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.) layers Items related to the Lambda Layers pipeline 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.

Feature request: provide custom functions for JMESPath expressions
2 participants