-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(batch): Implementation of base batch processing classes (#1588)
* chore: init workspace * chore: init workspace * Initial base class implementation * Added BatchProcessor implementation, attempted fix for async * Added unit tests * Refactoring unit tests * Lint fix, updated docstrings * Added response and identifier typings * test(idempotency): improve integration tests for utility (#1591) * docs: new name * chore: rename e2e files * tests(idempotency): expand integration tests * chore(idempotency): remove unreachable code * Removed unnecessary type casting * Moved exports for handlers and factories * Updated imports, refactored randomization in factories * Refactored EventType to be const instead of enum * Refactored and added documentation for errors * Removed debugging line * chore(ci): add canary to layer deployment (#1593) * docs(idempotency): write utility docs (#1592) * docs: base docs * wip * chore: added paths to snippets tsconfig * chore: added page to docs menu * docs(idempotency): utility docs * highlights * chore: remove CDK mention * build(internal): bump semver from 5.7.1 to 5.7.2 (#1594) Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md) - [Commits](npm/node-semver@v5.7.1...v5.7.2) --- updated-dependencies: - dependency-name: semver dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(idempotency): mark the utility ready public beta (#1595) * chore(idempotency): mark utility as public beta * chore: manually increment version in commons * docs(internal): update AWS SDK links to new docs (#1597) * chore(maintenance): remove parameters utility from layer bundling and layers e2e tests (#1599) * remove parameter from e2e tests * remove parameters from canary stack as well * chore(release): v1.11.1 [skip ci] * fix canary deploy in ci with correct workspace name (#1601) * chore: update layer ARN on documentation --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Andrea Amorosi <dreamorosi@gmail.com> Co-authored-by: Alexander Schueren <amelnyk@amazon.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Release bot[bot] <aws-devax-open-source@amazon.com>
- Loading branch information
1 parent
7f27b7c
commit 9d8df3d
Showing
73 changed files
with
3,835 additions
and
505 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,35 @@ | ||
import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middleware'; | ||
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; | ||
import middy from '@middy/core'; | ||
import type { Context } from 'aws-lambda'; | ||
import type { Request, Response } from './types'; | ||
|
||
const persistenceStore = new DynamoDBPersistenceLayer({ | ||
tableName: 'idempotencyTableName', | ||
keyAttr: 'idempotencyKey', | ||
expiryAttr: 'expiresAt', | ||
inProgressExpiryAttr: 'inProgressExpiresAt', | ||
statusAttr: 'currentStatus', | ||
dataAttr: 'resultData', | ||
validationKeyAttr: 'validationKey', | ||
}); | ||
|
||
export const handler = middy( | ||
async (_event: Request, _context: Context): Promise<Response> => { | ||
try { | ||
// ... create payment | ||
|
||
return { | ||
paymentId: '1234567890', | ||
message: 'success', | ||
statusCode: 200, | ||
}; | ||
} catch (error) { | ||
throw new Error('Error creating payment'); | ||
} | ||
} | ||
).use( | ||
makeHandlerIdempotent({ | ||
persistenceStore, | ||
}) | ||
); |
This file contains 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,40 @@ | ||
import { randomUUID } from 'node:crypto'; | ||
import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middleware'; | ||
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; | ||
import middy from '@middy/core'; | ||
import type { Context } from 'aws-lambda'; | ||
import type { Request, Response, SubscriptionResult } from './types'; | ||
|
||
const persistenceStore = new DynamoDBPersistenceLayer({ | ||
tableName: 'idempotencyTableName', | ||
}); | ||
|
||
const createSubscriptionPayment = async ( | ||
event: Request | ||
): Promise<SubscriptionResult> => { | ||
// ... create payment | ||
return { | ||
id: randomUUID(), | ||
productId: event.productId, | ||
}; | ||
}; | ||
|
||
export const handler = middy( | ||
async (event: Request, _context: Context): Promise<Response> => { | ||
try { | ||
const payment = await createSubscriptionPayment(event); | ||
|
||
return { | ||
paymentId: payment.id, | ||
message: 'success', | ||
statusCode: 200, | ||
}; | ||
} catch (error) { | ||
throw new Error('Error creating payment'); | ||
} | ||
} | ||
).use( | ||
makeHandlerIdempotent({ | ||
persistenceStore, | ||
}) | ||
); |
This file contains 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,59 @@ | ||
import { randomUUID } from 'node:crypto'; | ||
import { | ||
makeIdempotent, | ||
IdempotencyConfig, | ||
} from '@aws-lambda-powertools/idempotency'; | ||
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; | ||
import type { Context } from 'aws-lambda'; | ||
import type { Request, Response, SubscriptionResult } from './types'; | ||
|
||
const persistenceStore = new DynamoDBPersistenceLayer({ | ||
tableName: 'idempotencyTableName', | ||
}); | ||
const config = new IdempotencyConfig({}); | ||
|
||
const reportSubscriptionMetrics = async ( | ||
_transactionId: string, | ||
_user: string | ||
): Promise<void> => { | ||
// ... send notification | ||
}; | ||
|
||
const createSubscriptionPayment = makeIdempotent( | ||
async ( | ||
transactionId: string, | ||
event: Request | ||
): Promise<SubscriptionResult> => { | ||
// ... create payment | ||
return { | ||
id: transactionId, | ||
productId: event.productId, | ||
}; | ||
}, | ||
{ | ||
persistenceStore, | ||
dataIndexArgument: 1, | ||
config, | ||
} | ||
); | ||
|
||
export const handler = async ( | ||
event: Request, | ||
context: Context | ||
): Promise<Response> => { | ||
config.registerLambdaContext(context); | ||
try { | ||
const transactionId = randomUUID(); | ||
const payment = await createSubscriptionPayment(transactionId, event); | ||
|
||
await reportSubscriptionMetrics(transactionId, event.user); | ||
|
||
return { | ||
paymentId: payment.id, | ||
message: 'success', | ||
statusCode: 200, | ||
}; | ||
} catch (error) { | ||
throw new Error('Error creating payment'); | ||
} | ||
}; |
This file contains 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,38 @@ | ||
import { randomUUID } from 'node:crypto'; | ||
import { makeIdempotent } from '@aws-lambda-powertools/idempotency'; | ||
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; | ||
import type { Context } from 'aws-lambda'; | ||
import type { Request, Response, SubscriptionResult } from './types'; | ||
|
||
const persistenceStore = new DynamoDBPersistenceLayer({ | ||
tableName: 'idempotencyTableName', | ||
}); | ||
|
||
const createSubscriptionPayment = async ( | ||
event: Request | ||
): Promise<SubscriptionResult> => { | ||
// ... create payment | ||
return { | ||
id: randomUUID(), | ||
productId: event.productId, | ||
}; | ||
}; | ||
|
||
export const handler = makeIdempotent( | ||
async (event: Request, _context: Context): Promise<Response> => { | ||
try { | ||
const payment = await createSubscriptionPayment(event); | ||
|
||
return { | ||
paymentId: payment.id, | ||
message: 'success', | ||
statusCode: 200, | ||
}; | ||
} catch (error) { | ||
throw new Error('Error creating payment'); | ||
} | ||
}, | ||
{ | ||
persistenceStore, | ||
} | ||
); |
Oops, something went wrong.