-
Notifications
You must be signed in to change notification settings - Fork 157
feat(jmespath): add JMESPath utility #2135
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
Closed
Changes from all commits
Commits
Show all changes
104 commits
Select commit
Hold shift + click to select a range
5687ca0
feat(logger): Support for external observability providers (#1511)
erikayao93 e4ab44a
feat(logger): Support for external observability providers (#1511)
erikayao93 9d98c86
chore(logger): PowertoolsLogFormatter docstring and variable naming u…
erikayao93 6d1bfba
chore(maintenance): bump dependencies & drop nodejs14x (#1687)
dreamorosi e6279bb
chore: update release script to mark all utilities as alpha
dreamorosi dc44030
chore: release version change
dreamorosi dc3f642
chore: release version change
dreamorosi 67e5e94
chore(maintenance): remove `createLogger` and `createTracer` helpers …
dreamorosi 9e3a811
feat(logger): add esmodule support (#1734)
antstanley 74842c8
feat(commons): add esmodule support (#1735)
dreamorosi 54b3f27
feat(internal): add esmodule support (#1738)
dreamorosi 1f41355
chore(ci): v2 release line
dreamorosi 0f52ad1
chore(ci): fix alpha versioning pre-release
dreamorosi 0d82499
docs(maintenance): add processes tab (#1747)
dreamorosi b4853de
chore: remove extra comma
dreamorosi 9f50daa
chore(logger): refactor types and interfaces (#1758)
dreamorosi b08e589
chore(maintenance): bump Middy v4 & run tests (#1760)
dreamorosi cf8750f
chore(layers) widen version check in e2e
dreamorosi 60c816f
chore(maintenance): enable `isolatedModules` and isolate cache (#1765)
dreamorosi 0f29fea
fix: idempotency types
dreamorosi 6275601
build(maintenance): bump aws sdk dev dependencies
dreamorosi 2931c5a
fix(metrics): deduplicate dimensions when serialising (#1780)
am29d e32f74a
chore(release): v1.14.2 [skip ci]
github-actions[bot] 8cef57d
chore(release): v1.15.0 [skip ci]
github-actions[bot] 12bd0e0
chore(release): v1.16.0 [skip ci]
github-actions[bot] ec76a4f
chore(maintenance): drop support for Node.js 14 (#1802)
dreamorosi 0fe1db1
chore: package lock
dreamorosi 7240afa
chore(maintenance): add --require-hashes flag to pip installs (#1827)
dreamorosi e5d271d
bump version to 9.5.2, rerun pip-compile with correct deps (#1830)
am29d 32f5835
chore(ci): Dependabot fine tuning (#1862)
am29d 6ed197b
chore(deps-dev): bump @aws-sdk/client-cloudwatch from 3.438.0 to 3.48…
dependabot[bot] d9efd4a
chore(deps): fix dependencies and dependabot config (#1917)
dreamorosi abc7c3f
chore(deps-dev): bump @typescript-eslint/parser from 6.19.0 to 6.19.1…
dependabot[bot] 330d9f9
chore(deps-dev): bump @typescript-eslint/eslint-plugin (#1948)
dependabot[bot] 330a65c
chore(ci): refactor workflows to scope permissions (#1978)
dreamorosi 96888ec
chore(maintenance): rebase conflicts
dreamorosi 013e230
chore(maintenance): rebase conflicts
dreamorosi 0f6191d
chore: remove v2 specific release
dreamorosi 309fc4d
chore: release patch script
dreamorosi a31bc25
chore: address SonarCloud findings
dreamorosi bf0f57c
chore: remove unused dependency
dreamorosi 038b926
wip: jmespath util
dreamorosi 3679907
tests: spec compliance tests
dreamorosi e3c669d
wip: jmespath util
dreamorosi 2691dcd
wip: jmespath util
dreamorosi 6eaff37
chore: remove visitor class
dreamorosi 31acfab
wip: jmespath functions
dreamorosi 5d9154d
wip: jmespath functions
dreamorosi da42d54
wip: jmespath treeinterpreter
dreamorosi 30c9eca
chore: exports
dreamorosi f53ac17
tests: added group header
dreamorosi 46a0656
tests: 68% compliance with spec
dreamorosi c79d900
feat: error handling
dreamorosi 4debde4
chore: lock
dreamorosi b84e543
chore: package.json
dreamorosi c38ecc0
feat: handle negative indexes
dreamorosi 0f99c29
feat: filters and literal compliance
dreamorosi a5e31ab
chore: bumped
dreamorosi f37686f
feat: slice compliance
dreamorosi 5a7a4b7
chore: isMax
dreamorosi 9143b30
feat: min max and others
dreamorosi 0fb7108
feat: map function
dreamorosi 323e057
feat: toString, toArray, & toNumber functions
dreamorosi 12175e6
feat: sum function
dreamorosi fec4af9
feat: notNull function
dreamorosi 9156752
feat: merge function
dreamorosi 14a42a9
feat: keys, values, sort functions
dreamorosi 5cc4775
feat: join function
dreamorosi 4672bf5
feat: reverse function
dreamorosi ecb5f8b
feat: sort_by function
dreamorosi dad71c3
feat: max_by and min_by function
dreamorosi 9f4d4fd
chore: test setup
dreamorosi 76b5c67
tests: coverage tests
dreamorosi 1c2032c
chore: update types to include object
dreamorosi f4103f3
docs(jmespath): documentation & tests
dreamorosi 1a7f567
chore: undo rebase changes
dreamorosi 2dcc515
chore: undo rebase changes
dreamorosi 2629606
chore: version
dreamorosi 8d008c4
chore: undo rebase changes
dreamorosi d7aebfb
test(commons): unit tests for new commons utils
dreamorosi 3b6eedf
chore: remove unused test
dreamorosi 8fdcdfe
docs(jmespath): docs for utility
dreamorosi 7c96062
chore: remove unused lines
dreamorosi b5c8a0d
docs: api docs
dreamorosi 68c4812
refactor: reduce function cognitive complexity
dreamorosi b230b00
refactor: reduce class methods cognitive complexity
dreamorosi eb235c6
refactor: reduce class methods cognitive complexity
dreamorosi 48e01f1
refactor: reduce class methods cognitive complexity
dreamorosi 52eb0e3
refactor: reduce code complexity
dreamorosi 2d4d0c6
Merge branch 'main' into feat/jmespath
dreamorosi 04c3e06
chore: consume eq sign
dreamorosi db19a63
chore: consume negative number
dreamorosi c0c93f2
chore: consume sq bracket
dreamorosi 4975d10
chore: consume identifier
dreamorosi 3439f3b
chore: reduce complexity
dreamorosi 79bd5f6
chore: reduce complexity
dreamorosi d5060d6
chore: reduce complexity
dreamorosi b108e28
chore: reduce complexity
dreamorosi 3d83aef
chore: reduce complexity
dreamorosi 7760b00
reduce complexity
dreamorosi 86a36a4
reduce complexity
dreamorosi f52ebd0
reduce complexity
dreamorosi 9678d6e
docs: add missing jsdoc
dreamorosi 300938e
chore: stabilize sort
dreamorosi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
docs/snippets/jmespath/extractDataFromBuiltinEnvelope.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"Records": [ | ||
{ | ||
"messageId": "19dd0b57-b21e-4ac1-bd88-01bbb068cb78", | ||
"receiptHandle": "MessageReceiptHandle", | ||
"body": "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\",\"booking\":{\"id\":\"5b2c4803-330b-42b7-811a-c68689425de1\",\"reference\":\"ySz7oA\",\"outboundFlightId\":\"20c0d2f2-56a3-4068-bf20-ff7703db552d\"},\"payment\":{\"receipt\":\"https://pay.stripe.com/receipts/acct_1Dvn7pF4aIiftV70/ch_3JTC14F4aIiftV700iFq2CHB/rcpt_K7QsrFln9FgFnzUuBIiNdkkRYGxUL0X\",\"amount\":100}}", | ||
"attributes": { | ||
"ApproximateReceiveCount": "1", | ||
"SentTimestamp": "1523232000000", | ||
"SenderId": "123456789012", | ||
"ApproximateFirstReceiveTimestamp": "1523232000001" | ||
}, | ||
"messageAttributes": {}, | ||
"md5OfBody": "7b270e59b47ff90a553787216d55d91d", | ||
"eventSource": "aws:sqs", | ||
"eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:MyQueue", | ||
"awsRegion": "us-east-1" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { | ||
extractDataFromEnvelope, | ||
SQS, | ||
} from '@aws-lambda-powertools/jmespath/envelopes'; | ||
import { Logger } from '@aws-lambda-powertools/logger'; | ||
import type { SQSEvent } from 'aws-lambda'; | ||
|
||
const logger = new Logger(); | ||
|
||
type MessageBody = { | ||
customerId: string; | ||
}; | ||
|
||
export const handler = async (event: SQSEvent): Promise<void> => { | ||
const records = extractDataFromEnvelope<Array<MessageBody>>(event, SQS); | ||
for (const record of records) { | ||
// records is now a list containing the deserialized body of each message | ||
const { customerId } = record; | ||
logger.appendKeys({ customerId }); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"body": "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\"}", | ||
"deeplyNested": [ | ||
{ | ||
"someData": [1, 2, 3] | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes'; | ||
|
||
type MyEvent = { | ||
body: string; // "{\"customerId\":\"dd4649e6-2484-4993-acb8-0f9123103394\"}" | ||
deeplyNested: Array<{ someData: number[] }>; | ||
}; | ||
|
||
type MessageBody = { | ||
customerId: string; | ||
}; | ||
|
||
export const handler = async (event: MyEvent): Promise<unknown> => { | ||
const payload = extractDataFromEnvelope<MessageBody>( | ||
event, | ||
'powertools_json(body)' | ||
); | ||
const { customerId } = payload; // now deserialized | ||
|
||
// also works for fetching and flattening deeply nested data | ||
const someData = extractDataFromEnvelope<number[]>( | ||
event, | ||
'deeplyNested[*].someData[]' | ||
); | ||
|
||
return { | ||
customerId, | ||
message: 'success', | ||
context: someData, | ||
statusCode: 200, | ||
}; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes'; | ||
import { Logger } from '@aws-lambda-powertools/logger'; | ||
|
||
const logger = new Logger(); | ||
|
||
export const handler = async (event: { payload: string }): Promise<void> => { | ||
const logGroup = extractDataFromEnvelope<string>( | ||
event, | ||
'powertools_base64_gzip(payload) | powertools_json(@).logGroup' | ||
); | ||
|
||
logger.info('Log group name', { logGroup }); | ||
}; |
3 changes: 3 additions & 0 deletions
3
docs/snippets/jmespath/powertoolsBase64GzipJmespathPayload.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"payload": "H4sIACZAXl8C/52PzUrEMBhFX2UILpX8tPbHXWHqIOiq3Q1F0ubrWEiakqTWofTdTYYB0YWL2d5zvnuTFellBIOedoiyKH5M0iwnlKH7HZL6dDB6ngLDfLFYctUKjie9gHFaS/sAX1xNEq525QxwFXRGGMEkx4Th491rUZdV3YiIZ6Ljfd+lfSyAtZloacQgAkqSJCGhxM6t7cwwuUGPz4N0YKyvO6I9WDeMPMSo8Z4Ca/kJ6vMEYW5f1MX7W1lVxaG8vqX8hNFdjlc0iCBBSF4ERT/3Pl7RbMGMXF2KZMh/C+gDpNS7RRsp0OaRGzx0/t8e0jgmcczyLCWEePhni/23JWalzjdu0a3ZvgEaNLXeugEAAA==" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes'; | ||
import { Logger } from '@aws-lambda-powertools/logger'; | ||
|
||
const logger = new Logger(); | ||
|
||
export const handler = async (event: { payload: string }): Promise<void> => { | ||
const data = extractDataFromEnvelope<string>( | ||
event, | ||
'powertools_json(powertools_base64(payload))' | ||
); | ||
|
||
logger.info('Decoded payload', { data }); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"payload": "eyJ1c2VyX2lkIjogMTIzLCAicHJvZHVjdF9pZCI6IDEsICJxdWFudGl0eSI6IDIsICJwcmljZSI6IDEwLjQwLCAiY3VycmVuY3kiOiAiVVNEIn0=" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Records": [ | ||
{ | ||
"application": "app", | ||
"datetime": "2022-01-01T00:00:00.000Z", | ||
"notification": "GyYA+AXhZKk/K5DkanoQSTYpSKMwwxXh8DRWVo9A1hLqAQ==" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { fromBase64 } from '@aws-lambda-powertools/commons/utils/base64'; | ||
import { extractDataFromEnvelope } from '@aws-lambda-powertools/jmespath/envelopes'; | ||
import { PowertoolsFunctions } from '@aws-lambda-powertools/jmespath/functions'; | ||
import { Logger } from '@aws-lambda-powertools/logger'; | ||
import { brotliDecompressSync } from 'node:zlib'; | ||
|
||
const logger = new Logger(); | ||
|
||
// prettier-ignore | ||
class CustomFunctions extends PowertoolsFunctions { | ||
@PowertoolsFunctions.signature({ // (1)! | ||
argumentsSpecs: [['string']], | ||
variadic: false, | ||
}) | ||
public funcDecodeBrotliCompression(value: string): string { // (2)! | ||
const encoded = fromBase64(value, 'base64'); | ||
const uncompressed = brotliDecompressSync(encoded); | ||
|
||
return uncompressed.toString(); | ||
} | ||
} | ||
|
||
export const handler = async (event: { payload: string }): Promise<void> => { | ||
const message = extractDataFromEnvelope<string>( | ||
event, | ||
'Records[*].decode_brotli_compression(notification) | [*].powertools_json(@).message', | ||
{ customFunctions: new CustomFunctions() } | ||
); | ||
|
||
logger.info('Decoded message', { message }); | ||
}; |
30 changes: 30 additions & 0 deletions
30
docs/snippets/jmespath/powertoolsJsonIdempotencyJmespath.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"version": "2.0", | ||
"routeKey": "ANY /createpayment", | ||
"rawPath": "/createpayment", | ||
"rawQueryString": "", | ||
"headers": { | ||
"Header1": "value1", | ||
"Header2": "value2" | ||
}, | ||
"requestContext": { | ||
"accountId": "123456789012", | ||
"apiId": "api-id", | ||
"domainName": "id.execute-api.us-east-1.amazonaws.com", | ||
"domainPrefix": "id", | ||
"http": { | ||
"method": "POST", | ||
"path": "/createpayment", | ||
"protocol": "HTTP/1.1", | ||
"sourceIp": "ip", | ||
"userAgent": "agent" | ||
}, | ||
"requestId": "id", | ||
"routeKey": "ANY /createpayment", | ||
"stage": "$default", | ||
"time": "10/Feb/2021:13:40:43 +0000", | ||
"timeEpoch": 1612964443723 | ||
}, | ||
"body": "{\"user\":\"xyz\",\"product_id\":\"123456789\"}", | ||
"isBase64Encoded": false | ||
} |
51 changes: 51 additions & 0 deletions
51
docs/snippets/jmespath/powertoolsJsonIdempotencyJmespath.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
IdempotencyConfig, | ||
makeIdempotent, | ||
} from '@aws-lambda-powertools/idempotency'; | ||
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; | ||
import type { APIGatewayEvent } from 'aws-lambda'; | ||
import { randomUUID } from 'node:crypto'; | ||
|
||
const persistenceStore = new DynamoDBPersistenceLayer({ | ||
tableName: 'IdempotencyTable', | ||
}); | ||
|
||
export const handler = makeIdempotent( | ||
async (event: APIGatewayEvent) => { | ||
const body = JSON.parse(event.body || '{}'); | ||
const { user, productId } = body; | ||
|
||
const result = await createSubscriptionPayment(user, productId); | ||
|
||
return { | ||
statusCode: 200, | ||
body: JSON.stringify({ | ||
paymentId: result.id, | ||
message: 'success', | ||
}), | ||
}; | ||
}, | ||
{ | ||
persistenceStore, | ||
config: new IdempotencyConfig({ | ||
eventKeyJmesPath: 'powertools_json(body)', | ||
}), | ||
} | ||
); | ||
|
||
const createSubscriptionPayment = async ( | ||
user: string, | ||
productId: string | ||
): Promise<{ id: string; message: string }> => { | ||
const payload = { user, productId }; | ||
const response = await fetch('https://httpbin.org/anything', { | ||
method: 'POST', | ||
body: JSON.stringify(payload), | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error('Failed to create subscription payment'); | ||
} | ||
|
||
return { id: randomUUID(), message: 'paid' }; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,4 @@ | |
"axios": "^1.6.7", | ||
"hashi-vault-js": "^0.4.14" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.