diff --git a/.github/workflows/reusable-run-linting-check-and-unit-tests.yml b/.github/workflows/reusable-run-linting-check-and-unit-tests.yml index 846b17673a..01438974e9 100644 --- a/.github/workflows/reusable-run-linting-check-and-unit-tests.yml +++ b/.github/workflows/reusable-run-linting-check-and-unit-tests.yml @@ -89,7 +89,7 @@ jobs: - name: Setup dependencies uses: ./.github/actions/cached-node-modules - name: Run linting - run: npm run lint -w docs/snippets + run: npm run lint -w examples/snippets check-docs: runs-on: ubuntu-latest env: diff --git a/README.md b/README.md index ecc403048d..2edc7eb9a4 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ You can use Powertools for AWS Lambda (TypeScript) by installing it with your fa ### Examples -You can find examples of how to use Powertools for AWS Lambda (TypeScript) in the [examples](https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/examples/app) directory. The application is a simple REST API that can be deployed via either AWS CDK or AWS SAM. +You can find examples of how to use Powertools for AWS Lambda (TypeScript) in the [examples](https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/examples) directory. The directory contains code snippets around certain features as well as an is a simple REST API application that can be deployed via either AWS CDK or AWS SAM. Community-contributed examples: diff --git a/docs/contributing/conventions.md b/docs/contributing/conventions.md index c7034ba386..cbac8d7aa5 100644 --- a/docs/contributing/conventions.md +++ b/docs/contributing/conventions.md @@ -34,7 +34,7 @@ Additionally, we try to share common runtime code between utilities to reduce ma There are also a few other workspaces that are not utilities published to npm, but that still share dependencies and/or runtime code with the utilities. These workspaces are: -* `docs/snippets`: contains the documentation code snippets +* `examples/snippets`: contains the documentation code snippets * `examples/app`: contains an example project that can be deployed via AWS CDK or AWS SAM * `layers`: contains the code used to build and publish the [Lambda layers](../index.md#lambda-layer) diff --git a/docs/core/logger.md b/docs/core/logger.md index ada54070a5..c9b95b8b25 100644 --- a/docs/core/logger.md +++ b/docs/core/logger.md @@ -37,7 +37,7 @@ The `Logger` utility must always be instantiated outside the Lambda handler. By === "handler.ts" ```typescript hl_lines="1 3" - --8<-- "docs/snippets/logger/basicUsage.ts" + --8<-- "examples/snippets/logger/basicUsage.ts" ``` ### Utility settings @@ -60,7 +60,7 @@ Check API docs to learn more about [Logger constructor options](https://docs.pow === "handler.ts" ```typescript hl_lines="1 4" - --8<-- "docs/snippets/logger/sam.ts" + --8<-- "examples/snippets/logger/sam.ts" ``` === "template.yaml" @@ -115,7 +115,7 @@ This functionality will include the following keys in your structured logs: Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}. ```typescript hl_lines="2 14" - --8<-- "docs/snippets/logger/middy.ts" + --8<-- "examples/snippets/logger/middy.ts" ``` === "Decorator" @@ -128,7 +128,7 @@ This functionality will include the following keys in your structured logs: If this is not the desired behavior, you can call the `logger.injectLambdaContext()` method directly in your handler. ```typescript hl_lines="8" - --8<-- "docs/snippets/logger/decorator.ts" + --8<-- "examples/snippets/logger/decorator.ts" ``` 1. Binding your handler method allows your handler to access `this` within the class methods. @@ -136,7 +136,7 @@ This functionality will include the following keys in your structured logs: === "Manual" ```typescript hl_lines="10" - --8<-- "docs/snippets/logger/manual.ts" + --8<-- "examples/snippets/logger/manual.ts" ``` In each case, the printed log will look like this: @@ -168,13 +168,13 @@ When debugging in non-production environments, you can instruct Logger to log th === "Middy Middleware" ```typescript hl_lines="15" - --8<-- "docs/snippets/logger/eventMiddy.ts" + --8<-- "examples/snippets/logger/eventMiddy.ts" ``` === "Decorator" ```typescript hl_lines="8" - --8<-- "docs/snippets/logger/eventDecorator.ts" + --8<-- "examples/snippets/logger/eventDecorator.ts" ``` 1. Binding your handler method allows your handler to access `this` within the class methods. @@ -193,7 +193,7 @@ To remove the keys you added, you can use the `removeKeys` method. === "handler.ts" ```typescript hl_lines="5-13 17-25 32" - --8<-- "docs/snippets/logger/appendKeys.ts" + --8<-- "examples/snippets/logger/appendKeys.ts" ``` === "Example CloudWatch Logs excerpt" @@ -239,13 +239,13 @@ If you want to make sure that persistent attributes added **inside the handler f === "Middy Middleware" ```typescript hl_lines="31" - --8<-- "docs/snippets/logger/clearStateMiddy.ts" + --8<-- "examples/snippets/logger/clearStateMiddy.ts" ``` === "Decorator" ```typescript hl_lines="16" - --8<-- "docs/snippets/logger/clearStateDecorator.ts" + --8<-- "examples/snippets/logger/clearStateDecorator.ts" ``` 1. Binding your handler method allows your handler to access `this` within the class methods. @@ -303,7 +303,7 @@ You can append additional data to a single log item by passing objects as additi === "handler.ts" ```typescript hl_lines="16-18 23-25 37" - --8<-- "docs/snippets/logger/extraData.ts" + --8<-- "examples/snippets/logger/extraData.ts" ``` === "Example CloudWatch Logs excerpt" @@ -356,7 +356,7 @@ The error will be logged with default key name `error`, but you can also pass yo === "handler.ts" ```typescript hl_lines="13 20-22" - --8<-- "docs/snippets/logger/logError.ts" + --8<-- "examples/snippets/logger/logError.ts" ``` === "Example CloudWatch Logs excerpt" @@ -414,7 +414,7 @@ We support the following log levels: You can access the current log level by using the `getLevelName()` method. This method returns the name of the current log level as a string. If you want to change the log level at runtime, you can use the `setLogLevel()` method. This method accepts a string value that represents the log level you want to set, both lower and upper case values are supported. ```typescript ---8<-- "docs/snippets/logger/logLevel.ts" +--8<-- "examples/snippets/logger/logLevel.ts" ``` If you want to access the numeric value of the current log level, you can use the `level` property. For example, if the current log level is `INFO`, `logger.level` property will return `12`. @@ -480,7 +480,7 @@ Once a child logger is created, the logger and its parent will act as separate i === "handler.ts" ```typescript hl_lines="16-18" - --8<-- "docs/snippets/logger/createChild.ts" + --8<-- "examples/snippets/logger/createChild.ts" ``` === "Example CloudWatch Logs excerpt" @@ -534,7 +534,7 @@ Sampling decision happens at the Logger initialization. This means sampling may === "handler.ts" ```typescript hl_lines="6" - --8<-- "docs/snippets/logger/logSampling.ts" + --8<-- "examples/snippets/logger/logSampling.ts" ``` === "Example CloudWatch Logs excerpt - Invocation #1" @@ -644,7 +644,7 @@ You can customize the structure (keys and values) of your log items by passing a === "handler.ts" ```typescript hl_lines="2 6" - --8<-- "docs/snippets/logger/bringYourOwnFormatterHandler.ts" + --8<-- "examples/snippets/logger/bringYourOwnFormatterHandler.ts" ``` This is how the `MyCompanyLogFormatter` (dummy name) would look like: @@ -652,7 +652,7 @@ This is how the `MyCompanyLogFormatter` (dummy name) would look like: === "utils/formatters/MyCompanyLogFormatter.ts" ```typescript - --8<-- "docs/snippets/logger/bringYourOwnFormatterClass.ts" + --8<-- "examples/snippets/logger/bringYourOwnFormatterClass.ts" ``` This is how the printed log would look: @@ -701,7 +701,7 @@ This is a Jest sample that provides the minimum information necessary for Logger === "handler.test.ts" ```typescript - --8<-- "docs/snippets/logger/unitTesting.ts" + --8<-- "examples/snippets/logger/unitTesting.ts" ``` ### Suppress logs with Jest diff --git a/docs/core/metrics.md b/docs/core/metrics.md index a626c85170..99ba6dbdc3 100644 --- a/docs/core/metrics.md +++ b/docs/core/metrics.md @@ -59,7 +59,7 @@ The `Metrics` utility must always be instantiated outside of the Lambda handler. === "handler.ts" ```typescript hl_lines="1 3-6" - --8<-- "docs/snippets/metrics/basicUsage.ts" + --8<-- "examples/snippets/metrics/basicUsage.ts" ``` ### Utility settings @@ -83,7 +83,7 @@ The `Metrics` utility is instantiated outside of the Lambda handler. In doing th === "handler.ts" ```typescript hl_lines="1 4" - --8<-- "docs/snippets/metrics/sam.ts" + --8<-- "examples/snippets/metrics/sam.ts" ``` === "template.yml" @@ -109,13 +109,13 @@ You can create metrics using the `addMetric` method, and you can create dimensio === "Metrics" ```typescript hl_lines="12" - --8<-- "docs/snippets/metrics/createMetrics.ts" + --8<-- "examples/snippets/metrics/createMetrics.ts" ``` === "Metrics with custom dimensions" ```typescript hl_lines="12-13" - --8<-- "docs/snippets/metrics/customDimensions.ts" + --8<-- "examples/snippets/metrics/customDimensions.ts" ``` !!! tip "Autocomplete Metric Units" @@ -137,7 +137,7 @@ You can create [high-resolution metrics](https://aws.amazon.com/about-aws/whats- === "Metrics with high resolution" ```typescript hl_lines="4 20" - --8<-- "docs/snippets/metrics/addHighResolutionMetric.ts" + --8<-- "examples/snippets/metrics/addHighResolutionMetric.ts" ``` !!! tip "Autocomplete Metric Resolutions" @@ -150,7 +150,7 @@ You can call `addMetric()` with the same name multiple times. The values will be === "addMetric() with the same name" ```typescript hl_lines="12 14" - --8<-- "docs/snippets/metrics/multiValueMetrics.ts" + --8<-- "examples/snippets/metrics/multiValueMetrics.ts" ``` === "Example CloudWatch Logs excerpt" @@ -195,7 +195,7 @@ You can add default dimensions to your metrics by passing them as parameters in === "constructor" ```typescript hl_lines="6" - --8<-- "docs/snippets/metrics/defaultDimensions.ts" + --8<-- "examples/snippets/metrics/defaultDimensions.ts" ``` === "Middy middleware" @@ -205,13 +205,13 @@ You can add default dimensions to your metrics by passing them as parameters in Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}. ```typescript hl_lines="24-26" - --8<-- "docs/snippets/metrics/defaultDimensionsMiddy.ts" + --8<-- "examples/snippets/metrics/defaultDimensionsMiddy.ts" ``` === "setDefaultDimensions method" ```typescript hl_lines="7" - --8<-- "docs/snippets/metrics/setDefaultDimensions.ts" + --8<-- "examples/snippets/metrics/setDefaultDimensions.ts" ``` === "with logMetrics decorator" @@ -224,7 +224,7 @@ You can add default dimensions to your metrics by passing them as parameters in If this is not the desired behavior, you can use the `logMetrics` middleware instead. ```typescript hl_lines="12" - --8<-- "docs/snippets/metrics/defaultDimensionsDecorator.ts" + --8<-- "examples/snippets/metrics/defaultDimensionsDecorator.ts" ``` 1. Binding your handler method allows your handler to access `this` within the class methods. @@ -258,7 +258,7 @@ See below an example of how to automatically flush metrics with the Middy-compat === "handler.ts" ```typescript hl_lines="2 17" - --8<-- "docs/snippets/metrics/middy.ts" + --8<-- "examples/snippets/metrics/middy.ts" ``` === "Example CloudWatch Logs excerpt" @@ -297,7 +297,7 @@ The `logMetrics` decorator of the metrics utility can be used when your Lambda h === "handler.ts" ```typescript hl_lines="10" - --8<-- "docs/snippets/metrics/decorator.ts" + --8<-- "examples/snippets/metrics/decorator.ts" ``` 1. Binding your handler method allows your handler to access `this` within the class methods. @@ -334,7 +334,7 @@ You can manually flush the metrics with `publishStoredMetrics` as follows: === "handler.ts" ```typescript hl_lines="13" - --8<-- "docs/snippets/metrics/manual.ts" + --8<-- "examples/snippets/metrics/manual.ts" ``` === "Example CloudWatch Logs excerpt" @@ -366,7 +366,7 @@ If you want to ensure that at least one metric is emitted before you flush them, === "handler.ts" ```typescript hl_lines="21" - --8<-- "docs/snippets/metrics/throwOnEmptyMetrics.ts" + --8<-- "examples/snippets/metrics/throwOnEmptyMetrics.ts" ``` ### Capturing a cold start invocation as metric @@ -376,13 +376,13 @@ You can optionally capture cold start metrics with the `logMetrics` middleware o === "Middy Middleware" ```typescript hl_lines="18" - --8<-- "docs/snippets/metrics/captureColdStartMetricMiddy.ts" + --8<-- "examples/snippets/metrics/captureColdStartMetricMiddy.ts" ``` === "logMetrics decorator" ```typescript hl_lines="10" - --8<-- "docs/snippets/metrics/captureColdStartMetricDecorator.ts" + --8<-- "examples/snippets/metrics/captureColdStartMetricDecorator.ts" ``` If it's a cold start invocation, this feature will: @@ -406,7 +406,7 @@ You can add high-cardinality data as part of your Metrics log with the `addMetad === "handler.ts" ```typescript hl_lines="15" - --8<-- "docs/snippets/metrics/addMetadata.ts" + --8<-- "examples/snippets/metrics/addMetadata.ts" ``` === "Example CloudWatch Logs excerpt" @@ -450,13 +450,13 @@ CloudWatch EMF uses the same dimensions across all your metrics. Use `singleMetr === "Middy Middleware" ```typescript hl_lines="21 23-24" - --8<-- "docs/snippets/metrics/singleMetricDifferentDimsMiddy.ts" + --8<-- "examples/snippets/metrics/singleMetricDifferentDimsMiddy.ts" ``` === "logMetrics decorator" ```typescript hl_lines="16 18-19" - --8<-- "docs/snippets/metrics/singleMetricDifferentDimsDecorator.ts" + --8<-- "examples/snippets/metrics/singleMetricDifferentDimsDecorator.ts" ``` 1. Binding your handler method allows your handler to access `this` within the class methods. diff --git a/docs/core/tracer.md b/docs/core/tracer.md index 057f53efca..dbc24b8568 100644 --- a/docs/core/tracer.md +++ b/docs/core/tracer.md @@ -39,7 +39,7 @@ The `Tracer` utility must always be instantiated outside of the Lambda handler. === "handler.ts" ```typescript hl_lines="1 3" - --8<-- "docs/snippets/tracer/basicUsage.ts" + --8<-- "examples/snippets/tracer/basicUsage.ts" ``` ### Utility settings @@ -64,7 +64,7 @@ The `Tracer` utility is instantiated outside of the Lambda handler. In doing thi === "handler.ts" ```typescript hl_lines="1 4" - --8<-- "docs/snippets/tracer/sam.ts" + --8<-- "examples/snippets/tracer/sam.ts" ``` === "template.yml" @@ -92,7 +92,7 @@ You can quickly start by importing the `Tracer` class, initialize it outside the Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}. ```typescript hl_lines="2 15 17" - --8<-- "docs/snippets/tracer/middy.ts" + --8<-- "examples/snippets/tracer/middy.ts" ``` === "Decorator" @@ -103,7 +103,7 @@ You can quickly start by importing the `Tracer` class, initialize it outside the Additionally, they are implemented to decorate async methods. When decorating a synchronous one, the decorator replaces its implementation with an async one causing the caller to have to `await` the now decorated method. ```typescript hl_lines="8" - --8<-- "docs/snippets/tracer/decorator.ts" + --8<-- "examples/snippets/tracer/decorator.ts" ``` 1. Binding your handler method allows your handler to access `this`. @@ -111,7 +111,7 @@ You can quickly start by importing the `Tracer` class, initialize it outside the === "Manual" ```typescript hl_lines="9-15 18-19 23 26 29-34" - --8<-- "docs/snippets/tracer/manual.ts" + --8<-- "examples/snippets/tracer/manual.ts" ``` When using the `captureLambdaHandler` decorator or middleware, Tracer performs these additional tasks to ease operations: @@ -131,7 +131,7 @@ When using the `captureLambdaHandler` decorator or middleware, Tracer performs t You can add annotations using `putAnnotation` method. ```typescript hl_lines="12" - --8<-- "docs/snippets/tracer/putAnnotation.ts" + --8<-- "examples/snippets/tracer/putAnnotation.ts" ``` 1. When Lambda starts an invocation [the X-Ray SDk creates a segment called `facade`](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-nodejs-subsegments.html#xray-sdk-nodejs-subsegments-lambda). @@ -141,7 +141,7 @@ When using the `captureLambdaHandler` decorator or middleware, Tracer performs t You can add metadata using `putMetadata` method. ```typescript hl_lines="12-14" - --8<-- "docs/snippets/tracer/putMetadata.ts" + --8<-- "examples/snippets/tracer/putMetadata.ts" ``` 1. When Lambda starts an invocation [the X-Ray SDk creates a segment called `facade`](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-nodejs-subsegments.html#xray-sdk-nodejs-subsegments-lambda). @@ -165,7 +165,7 @@ You can trace other class methods using the `captureMethod` decorator or any arb Additionally, they are implemented to decorate async methods. When decorating a synchronous one, the decorator replaces its implementation with an async one causing the caller to have to `await` the now decorated method. ```typescript hl_lines="8" - --8<-- "docs/snippets/tracer/captureMethodDecorator.ts" + --8<-- "examples/snippets/tracer/captureMethodDecorator.ts" ``` 1. You can set a custom name for the subsegment by passing `subSegmentName` to the decorator, like: `@tracer.captureMethod({ subSegmentName: '### myCustomMethod' })`. @@ -174,7 +174,7 @@ You can trace other class methods using the `captureMethod` decorator or any arb === "Manual" ```typescript hl_lines="6-12 18 21 25-30" - --8<-- "docs/snippets/tracer/captureMethodManual.ts" + --8<-- "examples/snippets/tracer/captureMethodManual.ts" ``` ### Patching AWS SDK clients @@ -189,7 +189,7 @@ You can patch any AWS SDK clients by calling the `captureAWSv3Client` method: === "index.ts" ```typescript hl_lines="6" - --8<-- "docs/snippets/tracer/captureAWSv3.ts" + --8<-- "examples/snippets/tracer/captureAWSv3.ts" ``` !!! info @@ -200,7 +200,7 @@ You can patch all AWS SDK v2 clients by calling the `captureAWS` method: === "index.ts" ```typescript hl_lines="7" - --8<-- "docs/snippets/tracer/captureAWSAll.ts" + --8<-- "examples/snippets/tracer/captureAWSAll.ts" ``` If you're looking to shave a few microseconds, or milliseconds depending on your function memory configuration, you can patch only specific AWS SDK v2 clients using `captureAWSClient`: @@ -208,7 +208,7 @@ If you're looking to shave a few microseconds, or milliseconds depending on your === "index.ts" ```typescript hl_lines="6" - --8<-- "docs/snippets/tracer/captureAWS.ts" + --8<-- "examples/snippets/tracer/captureAWS.ts" ``` ### Tracing HTTP requests @@ -223,8 +223,8 @@ You can opt-out from this feature by setting the **`POWERTOOLS_TRACER_CAPTURE_HT === "index.ts" - ```typescript hl_lines="2" - --8<-- "docs/snippets/tracer/captureHTTP.ts" + ```typescript + --8<-- "examples/snippets/tracer/captureHTTP.ts" ``` ```json hl_lines="6 9 12-21" @@ -272,19 +272,19 @@ Alternatively, use the `captureResponse: false` option in both `tracer.captureLa === "method.ts" ```typescript hl_lines="7" - --8<-- "docs/snippets/tracer/disableCaptureResponseMethod.ts" + --8<-- "examples/snippets/tracer/disableCaptureResponseMethod.ts" ``` === "handler.ts" ```typescript hl_lines="7" - --8<-- "docs/snippets/tracer/disableCaptureResponseHandler.ts" + --8<-- "examples/snippets/tracer/disableCaptureResponseHandler.ts" ``` === "middy.ts" ```typescript hl_lines="18" - --8<-- "docs/snippets/tracer/disableCaptureResponseMiddy.ts" + --8<-- "examples/snippets/tracer/disableCaptureResponseMiddy.ts" ``` ### Disabling errors auto-capture @@ -306,8 +306,8 @@ Tracer exposes a `getRootXrayTraceId()` method that allows you to retrieve the [ === "index.ts" - ```typescript hl_lines="11" - --8<-- "docs/snippets/tracer/accessRootTraceId.ts" + ```typescript hl_lines="9" + --8<-- "examples/snippets/tracer/accessRootTraceId.ts" ``` ### Escape hatch mechanism @@ -319,7 +319,7 @@ This is useful when you need a feature available in X-Ray that is not available === "index.ts" ```typescript hl_lines="7" - --8<-- "docs/snippets/tracer/escapeHatch.ts" + --8<-- "examples/snippets/tracer/escapeHatch.ts" ``` ## Testing your code diff --git a/docs/snippets/tracer/captureHTTP.ts b/docs/snippets/tracer/captureHTTP.ts deleted file mode 100644 index 5c12693839..0000000000 --- a/docs/snippets/tracer/captureHTTP.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Tracer } from '@aws-lambda-powertools/tracer'; - -new Tracer({ serviceName: 'serverlessAirline' }); - -export const handler = async ( - _event: unknown, - _context: unknown -): Promise => { - await fetch('https://httpbin.org/status/200'); -}; diff --git a/docs/snippets/tsconfig.json b/docs/snippets/tsconfig.json deleted file mode 100644 index 7c921276c8..0000000000 --- a/docs/snippets/tsconfig.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "rootDir": "./", - "baseUrl": ".", - "noEmit": true, - "noUnusedLocals": false, - "allowUnusedLabels": true, - "paths": { - "@aws-lambda-powertools/parameters/ssm": [ - "../../packages/parameters/lib/ssm" - ], - "@aws-lambda-powertools/parameters/secrets": [ - "../../packages/parameters/lib/secrets" - ], - "@aws-lambda-powertools/parameters/appconfig": [ - "../../packages/parameters/lib/appconfig" - ], - "@aws-lambda-powertools/parameters/dynamodb": [ - "../../packages/parameters/lib/dynamodb" - ], - "@aws-lambda-powertools/idempotency/dynamodb": [ - "../../packages/idempotency/lib/persistence/DynamoDBPersistenceLayer" - ], - "@aws-lambda-powertools/idempotency/persistence": [ - "../../packages/idempotency/lib/persistence" - ], - "@aws-lambda-powertools/idempotency": ["../../packages/idempotency/lib"], - "@aws-lambda-powertools/idempotency/middleware": [ - "../../packages/idempotency/lib/middleware" - ], - "@aws-lambda-powertools/batch": ["../../packages/batch/lib"], - "@aws-lambda-powertools/jmespath": ["../../packages/jmespath/lib"], - "@aws-lambda-powertools/jmespath/envelopes": [ - "../../packages/jmespath/lib/envelopes" - ], - "@aws-lambda-powertools/parser": ["../../packages/parser/lib"], - "@aws-lambda-powertools/logger": ["../../packages/logger/lib"] - } - } -} diff --git a/docs/utilities/batch.md b/docs/utilities/batch.md index be76460edc..c8e253492a 100644 --- a/docs/utilities/batch.md +++ b/docs/utilities/batch.md @@ -85,19 +85,19 @@ The remaining sections of the documentation will rely on these samples. For comp === "SQS" ```yaml title="template.yaml" hl_lines="30-31" - --8<-- "docs/snippets/batch/templates/sam/sqs.yaml" + --8<-- "examples/snippets/batch/templates/sam/sqs.yaml" ``` === "Kinesis Data Streams" ```yaml title="template.yaml" hl_lines="44-45" - --8<-- "docs/snippets/batch/templates/sam/kinesis.yaml" + --8<-- "examples/snippets/batch/templates/sam/kinesis.yaml" ``` === "DynamoDB Streams" ```yaml title="template.yaml" hl_lines="43-44" - --8<-- "docs/snippets/batch/templates/sam/dynamodb.yaml" + --8<-- "examples/snippets/batch/templates/sam/dynamodb.yaml" ``` ### Processing messages from SQS @@ -115,9 +115,9 @@ Processing batches from SQS works in three stages: ```typescript hl_lines="1-5 14 17 29-31" --8<-- - docs/snippets/batch/gettingStartedSQS.ts::16 - docs/snippets/batch/gettingStartedSQS.ts:18:29 - docs/snippets/batch/gettingStartedSQS.ts:31:34 + examples/snippets/batch/gettingStartedSQS.ts::16 + examples/snippets/batch/gettingStartedSQS.ts:18:29 + examples/snippets/batch/gettingStartedSQS.ts:31:34 --8<-- ``` @@ -130,13 +130,13 @@ Processing batches from SQS works in three stages: The second record failed to be processed, therefore the processor added its message ID in the response. ```json - --8<-- "docs/snippets/batch/samples/sampleSQSResponse.json" + --8<-- "examples/snippets/batch/samples/sampleSQSResponse.json" ``` === "Sample event" ```json - --8<-- "docs/snippets/batch/samples/sampleSQSEvent.json" + --8<-- "examples/snippets/batch/samples/sampleSQSEvent.json" ``` #### FIFO queues @@ -145,7 +145,7 @@ When using [SQS FIFO queues](https://docs.aws.amazon.com/AWSSimpleQueueService/l This helps preserve the ordering of messages in your queue. ```typescript hl_lines="1-4 13 28-30" ---8<-- "docs/snippets/batch/gettingStartedSQSFifo.ts" +--8<-- "examples/snippets/batch/gettingStartedSQSFifo.ts" ``` 1. **Step 1**. Creates a partial failure batch processor for SQS FIFO queues. See [partial failure mechanics for details](#partial-failure-mechanics) @@ -168,7 +168,7 @@ Processing batches from Kinesis works in three stages: === "index.ts" ```typescript hl_lines="1-5 14 17 27-29" - --8<-- "docs/snippets/batch/gettingStartedKinesis.ts" + --8<-- "examples/snippets/batch/gettingStartedKinesis.ts" ``` 1. **Step 1**. Creates a partial failure batch processor for Kinesis Data Streams. See [partial failure mechanics for details](#partial-failure-mechanics) @@ -178,13 +178,13 @@ Processing batches from Kinesis works in three stages: The second record failed to be processed, therefore the processor added its sequence number in the response. ```json - --8<-- "docs/snippets/batch/samples/sampleKinesisEvent.json" + --8<-- "examples/snippets/batch/samples/sampleKinesisEvent.json" ``` === "Sample event" ```json - --8<-- "docs/snippets/batch/samples/sampleKinesisResponse.json" + --8<-- "examples/snippets/batch/samples/sampleKinesisResponse.json" ``` ### Processing messages from DynamoDB @@ -201,7 +201,7 @@ Processing batches from DynamoDB Streams works in three stages: === "index.ts" ```typescript hl_lines="1-5 14 17 32-34" - --8<-- "docs/snippets/batch/gettingStartedDynamoDBStreams.ts" + --8<-- "examples/snippets/batch/gettingStartedDynamoDBStreams.ts" ``` 1. **Step 1**. Creates a partial failure batch processor for DynamoDB Streams. See [partial failure mechanics for details](#partial-failure-mechanics) @@ -211,13 +211,13 @@ Processing batches from DynamoDB Streams works in three stages: The second record failed to be processed, therefore the processor added its sequence number in the response. ```json - --8<-- "docs/snippets/batch/samples/sampleDynamoDBStreamsResponse.json" + --8<-- "examples/snippets/batch/samples/sampleDynamoDBStreamsResponse.json" ``` === "Sample event" ```json - --8<-- "docs/snippets/batch/samples/sampleDynamoDBStreamsEvent.json" + --8<-- "examples/snippets/batch/samples/sampleDynamoDBStreamsEvent.json" ``` ### Error handling @@ -228,9 +228,9 @@ By default, we catch any exception raised by your record handler function. This ```typescript hl_lines="30" --8<-- - docs/snippets/batch/gettingStartedErrorHandling.ts::29 - docs/snippets/batch/gettingStartedErrorHandling.ts:31:38 - docs/snippets/batch/gettingStartedErrorHandling.ts:40:43 + examples/snippets/batch/gettingStartedErrorHandling.ts::29 + examples/snippets/batch/gettingStartedErrorHandling.ts:31:38 + examples/snippets/batch/gettingStartedErrorHandling.ts:40:43 --8<-- ``` @@ -241,7 +241,7 @@ By default, we catch any exception raised by your record handler function. This === "Sample response" ```json - --8<-- "docs/snippets/batch/samples/sampleSQSResponse.json" + --8<-- "examples/snippets/batch/samples/sampleSQSResponse.json" ``` ### Partial failure mechanics @@ -398,7 +398,7 @@ Use the `BatchProcessor` directly in your function to access a list of all retur * **When failed**. We will include a tuple with `fail`, exception as a string, and the batch record ```typescript hl_lines="25 27-28 30-33 38" title="Accessing processed messages" ---8<-- "docs/snippets/batch/accessProcessedMessages.ts" +--8<-- "examples/snippets/batch/accessProcessedMessages.ts" ``` 1. The processor requires the records array. This is typically handled by `processPartialResponse`. @@ -411,7 +411,7 @@ Within your `recordHandler` function, you might need access to the Lambda contex We can automatically inject the [Lambda context](https://docs.aws.amazon.com/lambda/latest/dg/typescript-context.html){target="_blank"} into your `recordHandler` as optional second argument if you register it when using `BatchProcessorSync` or the `processPartialResponseSync` function. ```typescript hl_lines="17 35" ---8<-- "docs/snippets/batch/accessLambdaContext.ts" +--8<-- "examples/snippets/batch/accessLambdaContext.ts" ``` ### Extending BatchProcessor @@ -426,7 +426,7 @@ For these scenarios, you can subclass `BatchProcessor` and quickly override `suc Let's suppose you'd like to add a metric named `BatchRecordFailures` for each batch record that failed processing ```typescript hl_lines="3 20 24 31 37" title="Extending failure handling mechanism in BatchProcessor" ---8<-- "docs/snippets/batch/extendingFailure.ts" +--8<-- "examples/snippets/batch/extendingFailure.ts" ``` ### Create your own partial processor @@ -463,7 +463,7 @@ classDiagram You can then use this class as a context manager, or pass it to `processPartialResponseSync` to process the records in your Lambda handler function. ```typescript hl_lines="21 35 56 61 73 86" title="Creating a custom batch processor" ---8<-- "docs/snippets/batch/customPartialProcessor.ts" +--8<-- "examples/snippets/batch/customPartialProcessor.ts" ``` ## Tracing with AWS X-Ray @@ -471,7 +471,7 @@ You can then use this class as a context manager, or pass it to `processPartialR You can use Tracer to create subsegments for each batch record processed. To do so, you can open a new subsegment for each record, and close it when you're done processing it. When adding annotations and metadata to the subsegment, you can do so directly without calling `tracer.setSegment(subsegment)`. This allows you to work with the subsegment directly and avoid having to either pass the parent subsegment around or have to restore the parent subsegment at the end of the record processing. ```typescript ---8<-- "docs/snippets/batch/advancedTracingRecordHandler.ts" +--8<-- "examples/snippets/batch/advancedTracingRecordHandler.ts" ``` 1. Retrieve the current segment, then create a subsegment for the record being processed @@ -489,17 +489,17 @@ Given a SQS batch where the first batch record succeeds and the second fails pro === "index.test.ts" ```typescript - --8<-- "docs/snippets/batch/testingYourCode.ts" + --8<-- "examples/snippets/batch/testingYourCode.ts" ``` === "index.ts" ```typescript - --8<-- "docs/snippets/batch/gettingStartedSQS.ts" + --8<-- "examples/snippets/batch/gettingStartedSQS.ts" ``` === "Sample SQS event" ```json title="events/sqs_event.json" - --8<-- "docs/snippets/batch/samples/sampleSQSEvent.json" + --8<-- "examples/snippets/batch/samples/sampleSQSEvent.json" ``` diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index 34f1ba905f..9053c0424d 100644 --- a/docs/utilities/idempotency.md +++ b/docs/utilities/idempotency.md @@ -88,20 +88,20 @@ If you're not [changing the default configuration for the DynamoDB persistence l === "AWS Cloud Development Kit (CDK) example" - ```typescript title="template.tf" hl_lines="11-18 26" - --8<-- "docs/snippets/idempotency/templates/tableCdk.ts" + ```typescript title="template.ts" hl_lines="11-18 25" + --8<-- "examples/snippets/idempotency/templates/tableCdk.ts" ``` === "AWS Serverless Application Model (SAM) example" - ```yaml title="template.yaml" hl_lines="6-14 24-31" - --8<-- "docs/snippets/idempotency/templates/tableSam.yaml" + ```yaml title="template.yaml" hl_lines="6-14" + --8<-- "examples/snippets/idempotency/templates/tableSam.yaml" ``` === "Terraform example" ```terraform title="template.tf" hl_lines="14-26 64-70" - --8<-- "docs/snippets/idempotency/templates/tableTerraform.tf" + --8<-- "examples/snippets/idempotency/templates/tableTerraform.tf" ``` ???+ warning "Warning: Large responses with DynamoDB persistence layer" @@ -123,13 +123,13 @@ You can quickly start by initializing the `DynamoDBPersistenceLayer` class and u === "index.ts" ```typescript hl_lines="2-3 21 35-38" - --8<-- "docs/snippets/idempotency/makeIdempotentBase.ts" + --8<-- "examples/snippets/idempotency/makeIdempotentBase.ts" ``` === "types.ts" ```typescript - --8<-- "docs/snippets/idempotency/types.ts:3:16" + --8<-- "examples/snippets/idempotency/types.ts:3:16" ``` After processing this request successfully, a second request containing the exact same payload above will now return the same response, ensuring our customer isn't charged twice. @@ -149,13 +149,13 @@ When using `makeIdempotent` on arbitrary functions, you can tell us which argume === "index.ts" ```typescript hl_lines="22 34-38" - --8<-- "docs/snippets/idempotency/makeIdempotentAnyFunction.ts" + --8<-- "examples/snippets/idempotency/makeIdempotentAnyFunction.ts" ``` === "types.ts" ```typescript - --8<-- "docs/snippets/idempotency/types.ts:3:16" + --8<-- "examples/snippets/idempotency/types.ts:3:16" ``` The function this example has two arguments, note that while wrapping it with the `makeIdempotent` high-order function, we specify the `dataIndexArgument` as `1` to tell the decorator that the second argument is the one with the data we should use to make the function idempotent. Remember that arguments are zero-indexed, so the first argument is `0`, the second is `1`, etc. @@ -174,13 +174,13 @@ You can also use the `@idempotent` decorator to make your Lambda handler idempot === "index.ts" ```typescript hl_lines="17" - --8<-- "docs/snippets/idempotency/idempotentDecoratorBase.ts" + --8<-- "examples/snippets/idempotency/idempotentDecoratorBase.ts" ``` === "types.ts" ```typescript - --8<-- "docs/snippets/idempotency/types.ts" + --8<-- "examples/snippets/idempotency/types.ts" ``` You can use the decorator on your Lambda handler or on any function that returns a response to make it idempotent. This is useful when you want to make a specific logic idempotent, for example when your Lambda handler performs multiple side effects and you only want to make a specific one idempotent. @@ -199,13 +199,13 @@ Similar to the `makeIdempotent` function wrapper, you can quickly make your Lamb === "index.ts" ```typescript hl_lines="22 36-40" - --8<-- "docs/snippets/idempotency/makeHandlerIdempotent.ts" + --8<-- "examples/snippets/idempotency/makeHandlerIdempotent.ts" ``` === "types.ts" ```typescript - --8<-- "docs/snippets/idempotency/types.ts:3:16" + --8<-- "examples/snippets/idempotency/types.ts:3:16" ``` ### Choosing a payload subset for idempotency @@ -228,19 +228,19 @@ Imagine the function executes successfully, but the client never receives the re === "index.ts" ```typescript hl_lines="4 27 49" - --8<-- "docs/snippets/idempotency/makeIdempotentJmes.ts" + --8<-- "examples/snippets/idempotency/makeIdempotentJmes.ts" ``` === "Example event" ```json hl_lines="28" - --8<-- "docs/snippets/idempotency/samples/makeIdempotentJmes.json" + --8<-- "examples/snippets/idempotency/samples/makeIdempotentJmes.json" ``` === "types.ts" ```typescript - --8<-- "docs/snippets/idempotency/types.ts:3:16" + --8<-- "examples/snippets/idempotency/types.ts:3:16" ``` ### Lambda timeouts @@ -261,7 +261,7 @@ Here is an example on how you register the Lambda context in your handler: === "Registering Lambda Context" ```typescript hl_lines="13 38" - --8<-- "docs/snippets/idempotency/makeIdempotentLambdaContext.ts" + --8<-- "examples/snippets/idempotency/makeIdempotentLambdaContext.ts" ``` ### Handling exceptions @@ -295,7 +295,7 @@ If an error is thrown _outside_ the scope of the decorated function and after yo === "Handling exceptions" ```typescript hl_lines="39-40 47-48" - --8<-- "docs/snippets/idempotency/workingWithExceptions.ts" + --8<-- "examples/snippets/idempotency/workingWithExceptions.ts" ``` ???+ warning @@ -514,7 +514,7 @@ This persistence layer is built-in, and you can either use an existing DynamoDB === "Customizing DynamoDBPersistenceLayer to suit your table structure" ```typescript hl_lines="7-15" - --8<-- "docs/snippets/idempotency/customizePersistenceLayer.ts" + --8<-- "examples/snippets/idempotency/customizePersistenceLayer.ts" ``` When using DynamoDB as a persistence layer, you can alter the attribute names by passing these parameters when initializing the persistence layer: @@ -566,7 +566,7 @@ You can enable in-memory caching with the **`useLocalCache`** parameter: === "Caching idempotent transactions in-memory to prevent multiple calls to storage" ```typescript hl_lines="12-13" - --8<-- "docs/snippets/idempotency/workingWithLocalCache.ts" + --8<-- "examples/snippets/idempotency/workingWithLocalCache.ts" ``` When enabled, the default is to cache a maximum of 256 records in each Lambda execution environment - You can change it with the **`maxLocalCacheSize`** parameter. @@ -582,7 +582,7 @@ You can change this window with the **`expiresAfterSeconds`** parameter: === "Adjusting idempotency record expiration" ```typescript hl_lines="14" - --8<-- "docs/snippets/idempotency/workingWithRecordExpiration.ts" + --8<-- "examples/snippets/idempotency/workingWithRecordExpiration.ts" ``` This will mark any records older than 5 minutes as expired, and [your function will be executed as normal if it is invoked with a matching payload](#expired-idempotency-records). @@ -610,7 +610,7 @@ With **`payloadValidationJmesPath`**, you can provide an additional JMESPath exp === "Payload validation" ```typescript hl_lines="14-15" - --8<-- "docs/snippets/idempotency/workingWithPayloadValidation.ts" + --8<-- "examples/snippets/idempotency/workingWithPayloadValidation.ts" ``` In this example, the **`userId`** and **`productId`** keys are used as the payload to generate the idempotency key, as per **`eventKeyJmespath`** parameter. @@ -634,19 +634,19 @@ This means that we will raise **`IdempotencyKeyError`** if the evaluation of **` === "Idempotency key required" ```typescript hl_lines="14-15" - --8<-- "docs/snippets/idempotency/workingWithIdempotencyRequiredKey.ts" + --8<-- "examples/snippets/idempotency/workingWithIdempotencyRequiredKey.ts" ``` === "Success Event" ```json hl_lines="3 6" - --8<-- "docs/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeySuccess.json" + --8<-- "examples/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeySuccess.json" ``` === "Failure Event" ```json hl_lines="3 5" - --8<-- "docs/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeyError.json" + --8<-- "examples/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeyError.json" ``` ### Batch integration @@ -661,13 +661,13 @@ This ensures that you process each record in an idempotent manner, and guard aga === "Integration with batch processor" ```typescript hl_lines="27 31-34 41" - --8<-- "docs/snippets/idempotency/workingWithBatch.ts" + --8<-- "examples/snippets/idempotency/workingWithBatch.ts" ``` === "Sample event" ```json hl_lines="4" - --8<-- "docs/snippets/idempotency/samples/workingWithBatch.json" + --8<-- "examples/snippets/idempotency/samples/workingWithBatch.json" ``` ### Customizing AWS SDK configuration @@ -677,13 +677,13 @@ The **`clientConfig`** and **`awsSdkV3Client`** parameters enable you to pass in === "Passing specific configuration" ```typescript hl_lines="8-10" - --8<-- "docs/snippets/idempotency/workingWithCustomConfig.ts" + --8<-- "examples/snippets/idempotency/workingWithCustomConfig.ts" ``` === "Passing custom DynamoDBClient" ```typescript hl_lines="7-9 12" - --8<-- "docs/snippets/idempotency/workingWithCustomClient.ts" + --8<-- "examples/snippets/idempotency/workingWithCustomClient.ts" ``` ### Using a DynamoDB table with a composite primary key @@ -697,7 +697,7 @@ You can optionally set a static value for the partition key using the `staticPkV === "Reusing a DynamoDB table that uses a composite primary key" ```typescript hl_lines="9" - --8<-- "docs/snippets/idempotency/workingWithCompositeKey.ts" + --8<-- "examples/snippets/idempotency/workingWithCompositeKey.ts" ``` The example function above would cause data to be stored in DynamoDB like this: @@ -724,19 +724,19 @@ Below an example implementation of a custom persistence layer backed by a generi === "CustomPersistenceLayer" ```typescript hl_lines="9 19 28 34 50 90" - --8<-- "docs/snippets/idempotency/advancedBringYourOwnPersistenceLayer.ts" + --8<-- "examples/snippets/idempotency/advancedBringYourOwnPersistenceLayer.ts" ``` === "index.ts" ```typescript hl_lines="10" - --8<-- "docs/snippets/idempotency/advancedBringYourOwnPersistenceLayerUsage.ts" + --8<-- "examples/snippets/idempotency/advancedBringYourOwnPersistenceLayerUsage.ts" ``` === "types.ts" ```typescript - --8<-- "docs/snippets/idempotency/types.ts" + --8<-- "examples/snippets/idempotency/types.ts" ``` ???+ danger diff --git a/docs/utilities/jmespath.md b/docs/utilities/jmespath.md index ee7f266941..e7e0bc6316 100644 --- a/docs/utilities/jmespath.md +++ b/docs/utilities/jmespath.md @@ -39,13 +39,13 @@ You can use the `extractDataFromEnvelope` function with any [JMESPath expression === "extractDataFromBuiltinEnvelope.ts" ```typescript hl_lines="1 13 17 20 22" - --8<-- "docs/snippets/jmespath/extractDataFromEnvelope.ts" + --8<-- "examples/snippets/jmespath/extractDataFromEnvelope.ts" ``` === "extractDataFromEnvelope.json" ```json - --8<-- "docs/snippets/jmespath/extractDataFromEnvelope.json" + --8<-- "examples/snippets/jmespath/extractDataFromEnvelope.json" ``` ### Built-in envelopes @@ -54,13 +54,13 @@ We provide built-in envelopes for popular AWS Lambda event sources to easily dec === "extractDataFromBuiltinEnvelope.ts" ```typescript hl_lines="2-3 15" - --8<-- "docs/snippets/jmespath/extractDataFromBuiltinEnvelope.ts" + --8<-- "examples/snippets/jmespath/extractDataFromBuiltinEnvelope.ts" ``` === "extractDataFromBuiltinEnvelope.json" ```json hl_lines="6 15" - --8<-- "docs/snippets/jmespath/extractDataFromBuiltinEnvelope.json" + --8<-- "examples/snippets/jmespath/extractDataFromBuiltinEnvelope.json" ``` These are all built-in envelopes you can use along with their expression as a reference: @@ -103,13 +103,13 @@ This sample will deserialize the JSON string within the `body` key before [Idemp === "powertoolsJsonIdempotencyJmespath.ts" ```ts hl_lines="31" - --8<-- "docs/snippets/jmespath/powertoolsJsonIdempotencyJmespath.ts" + --8<-- "examples/snippets/jmespath/powertoolsJsonIdempotencyJmespath.ts" ``` === "powertoolsJsonIdempotencyJmespath.json" ```json hl_lines="28" - --8<-- "docs/snippets/jmespath/powertoolsJsonIdempotencyJmespath.json" + --8<-- "examples/snippets/jmespath/powertoolsJsonIdempotencyJmespath.json" ``` #### `powertools_base64` function @@ -121,7 +121,7 @@ This sample will decode the base64 value within the `data` key, and deserialize === "powertoolsBase64Jmespath.ts" ```ts hl_lines="9" - --8<-- "docs/snippets/jmespath/powertoolsBase64Jmespath.ts" + --8<-- "examples/snippets/jmespath/powertoolsBase64Jmespath.ts" ``` 1. The `data` variable contains the decoded object that looks like this: @@ -138,7 +138,7 @@ This sample will decode the base64 value within the `data` key, and deserialize === "powertoolsBase64JmespathPayload.json" ```json - --8<-- "docs/snippets/jmespath/powertoolsBase64JmespathPayload.json" + --8<-- "examples/snippets/jmespath/powertoolsBase64JmespathPayload.json" ``` #### `powertools_base64_gzip` function @@ -150,7 +150,7 @@ This sample will decompress and decode base64 data from Cloudwatch Logs, then us === "powertoolsBase64GzipJmespath.ts" ```ts hl_lines="9" - --8<-- "docs/snippets/jmespath/powertoolsBase64GzipJmespath.ts" + --8<-- "examples/snippets/jmespath/powertoolsBase64GzipJmespath.ts" ``` 1. The `payload` key contains a JSON object that once decompressed and decoded looks like this: @@ -186,7 +186,7 @@ This sample will decompress and decode base64 data from Cloudwatch Logs, then us === "powertoolsBase64GzipJmespathPayload.json" ```json - --8<-- "docs/snippets/jmespath/powertoolsBase64GzipJmespathPayload.json" + --8<-- "examples/snippets/jmespath/powertoolsBase64GzipJmespathPayload.json" ``` ### Bring your own JMESPath function @@ -202,8 +202,8 @@ Here is an example of how to decompress messages compressed using the [Brotli co ```ts hl_lines="3 9 25-26" --8<-- - docs/snippets/jmespath/powertoolsCustomFunction.ts::8 - docs/snippets/jmespath/powertoolsCustomFunction.ts:10: + examples/snippets/jmespath/powertoolsCustomFunction.ts::8 + examples/snippets/jmespath/powertoolsCustomFunction.ts:10: --8<-- ``` @@ -214,5 +214,5 @@ Here is an example of how to decompress messages compressed using the [Brotli co === "powertoolsCustomFunction.json" ```json - --8<-- "docs/snippets/jmespath/powertoolsCustomFunction.json" + --8<-- "examples/snippets/jmespath/powertoolsCustomFunction.json" ``` diff --git a/docs/utilities/parameters.md b/docs/utilities/parameters.md index dc87c5f108..3507c515f2 100644 --- a/docs/utilities/parameters.md +++ b/docs/utilities/parameters.md @@ -71,7 +71,7 @@ This utility requires additional permissions to work as expected. You can retrieve a single parameter using the `getParameter` high-level function. ```typescript hl_lines="1 5" title="Fetching a single parameter from SSM" ---8<-- "docs/snippets/parameters/getParameter.ts" +--8<-- "examples/snippets/parameters/getParameter.ts" ``` For multiple parameters, you can use either: @@ -82,13 +82,13 @@ For multiple parameters, you can use either: === "getParameters" ```typescript hl_lines="1 8" title="Fetching multiple parameters by path from SSM" - --8<-- "docs/snippets/parameters/getParameters.ts" + --8<-- "examples/snippets/parameters/getParameters.ts" ``` === "getParametersByName" ```typescript hl_lines="1-2 4-11 15" title="Fetching multiple parameters by names from SSM" - --8<-- "docs/snippets/parameters/getParametersByName.ts" + --8<-- "examples/snippets/parameters/getParametersByName.ts" ``` ???+ tip "`getParametersByName` supports graceful error handling" @@ -101,7 +101,7 @@ For multiple parameters, you can use either: * Throw `GetParameterError` if any of your parameters is named `_errors` ```typescript hl_lines="9 13-15 18" ---8<-- "docs/snippets/parameters/getParametersByNameGracefulErrorHandling.ts" +--8<-- "examples/snippets/parameters/getParametersByNameGracefulErrorHandling.ts" ``` ### Fetching secrets @@ -109,7 +109,7 @@ For multiple parameters, you can use either: You can fetch secrets stored in Secrets Manager using `getSecret`. ```typescript hl_lines="1 5" title="Fetching secrets" ---8<-- "docs/snippets/parameters/getSecret.ts" +--8<-- "examples/snippets/parameters/getSecret.ts" ``` ### Fetching app configurations @@ -119,7 +119,7 @@ You can fetch application configurations in AWS AppConfig using `getAppConfig`. The following will retrieve the latest version and store it in the cache. ```typescript hl_lines="1 5-8" title="Fetching latest config from AppConfig" ---8<-- "docs/snippets/parameters/getAppConfig.ts" +--8<-- "examples/snippets/parameters/getAppConfig.ts" ``` ## Advanced @@ -134,7 +134,7 @@ You can adjust how long values should be kept in cache by using the param `maxAg If you want to set the same TTL for all parameters, you can set the `POWERTOOLS_PARAMETERS_MAX_AGE` environment variable. **This will override the default TTL of 5 seconds but can be overridden by the `maxAge` parameter**. ```typescript hl_lines="8 14" title="Caching parameters values in memory for longer than 5 seconds" ---8<-- "docs/snippets/parameters/adjustingCacheTTL.ts" +--8<-- "examples/snippets/parameters/adjustingCacheTTL.ts" ``` 1. Options passed to `get()`, `getMultiple()`, and `getParametersByName()` will override the values set in `POWERTOOLS_PARAMETERS_MAX_AGE` environment variable. @@ -147,7 +147,7 @@ You can adjust how long values should be kept in cache by using the param `maxAg If you'd like to always ensure you fetch the latest parameter from the store regardless if already available in cache, use the `forceFetch` parameter. ```typescript hl_lines="5" title="Forcefully fetching the latest parameter whether TTL has expired or not" ---8<-- "docs/snippets/parameters/forceFetch.ts" +--8<-- "examples/snippets/parameters/forceFetch.ts" ``` ### Built-in provider class @@ -160,7 +160,7 @@ For greater flexibility such as configuring the underlying SDK client used by bu #### SSMProvider ```typescript hl_lines="4-5" title="Example with SSMProvider for further extensibility" ---8<-- "docs/snippets/parameters/ssmProvider.ts" +--8<-- "examples/snippets/parameters/ssmProvider.ts" ``` The AWS Systems Manager Parameter Store provider supports two additional arguments for the `get()` and `getMultiple()` methods: @@ -174,7 +174,7 @@ The AWS Systems Manager Parameter Store provider supports two additional argumen If you want to always decrypt parameters, you can set the `POWERTOOLS_PARAMETERS_SSM_DECRYPT=true` environment variable. **This will override the default value of `false` but can be overridden by the `decrypt` parameter**. ```typescript hl_lines="6 12" title="Example with get() and getMultiple()" ---8<-- "docs/snippets/parameters/ssmProviderDecryptAndRecursive.ts" +--8<-- "examples/snippets/parameters/ssmProviderDecryptAndRecursive.ts" ``` 1. Options passed to `get()`, `getMultiple()`, and `getParametersByName()` will override the values set in `POWERTOOLS_PARAMETERS_SSM_DECRYPT` environment variable. @@ -182,7 +182,7 @@ The AWS Systems Manager Parameter Store provider supports two additional argumen #### SecretsProvider ```typescript hl_lines="4-5" title="Example with SecretsProvider for further extensibility" ---8<-- "docs/snippets/parameters/secretsProvider.ts" +--8<-- "examples/snippets/parameters/secretsProvider.ts" ``` #### AppConfigProvider @@ -195,7 +195,7 @@ The AWS AppConfig provider requires two arguments when initialized: | **environment** | Yes | _(N/A)_ | The environment that corresponds to your current config. | ```typescript hl_lines="4 8" title="Example with AppConfigProvider for further extensibility" ---8<-- "docs/snippets/parameters/appConfigProvider.ts" +--8<-- "examples/snippets/parameters/appConfigProvider.ts" ``` #### DynamoDBProvider @@ -218,14 +218,14 @@ With this table, `await dynamoDBProvider.get('my-param')` will return `my-value` === "handler.ts" ```typescript hl_lines="3 7" - --8<-- "docs/snippets/parameters/dynamoDBProvider.ts" + --8<-- "examples/snippets/parameters/dynamoDBProvider.ts" ``` === "DynamoDB Local example" You can initialize the DynamoDB provider pointing to [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html) using the `endpoint` field in the `clientConfig` parameter: ```typescript hl_lines="5-7" - --8<-- "docs/snippets/parameters/dynamoDBProviderLocal.ts" + --8<-- "examples/snippets/parameters/dynamoDBProviderLocal.ts" ``` **DynamoDB table structure for multiple values parameters** @@ -246,7 +246,7 @@ With this table, `await dynamoDBProvider.getMultiple('my-hash-key')` will return === "handler.ts" ```typescript hl_lines="3 10" - --8<-- "docs/snippets/parameters/dynamoDBProviderMultiple.ts" + --8<-- "examples/snippets/parameters/dynamoDBProviderMultiple.ts" ``` === "values response object" @@ -271,7 +271,7 @@ DynamoDB provider can be customized at initialization to match your table struct | **valueAttr** | No | `value` | Name of the attribute containing the parameter value. | ```typescript hl_lines="3-8" title="Customizing DynamoDBProvider to suit your table design" ---8<-- "docs/snippets/parameters/dynamoDBProviderCustomizeTable.ts" +--8<-- "examples/snippets/parameters/dynamoDBProviderCustomizeTable.ts" ``` ### Create your own provider @@ -284,17 +284,17 @@ Here's an example of implementing a custom parameter store using an external ser === "Provider implementation" ```typescript - --8<-- "docs/snippets/parameters/customProviderVault.ts" + --8<-- "examples/snippets/parameters/customProviderVault.ts" ``` === "Provider types" ```typescript - --8<-- "docs/snippets/parameters/customProviderVaultTypes.ts" + --8<-- "examples/snippets/parameters/customProviderVaultTypes.ts" ``` === "Provider usage" ```typescript - --8<-- "docs/snippets/parameters/customProviderVaultUsage.ts" + --8<-- "examples/snippets/parameters/customProviderVaultUsage.ts" ``` ### Deserializing values with transform parameter @@ -306,12 +306,12 @@ For parameters stored in JSON or Base64 format, you can use the `transform` argu === "High level functions" ```typescript hl_lines="4" - --8<-- "docs/snippets/parameters/transform.ts" + --8<-- "examples/snippets/parameters/transform.ts" ``` === "Providers" ```typescript hl_lines="7 10" - --8<-- "docs/snippets/parameters/transformProvider.ts" + --8<-- "examples/snippets/parameters/transformProvider.ts" ``` #### Partial transform failures with `getMultiple()` @@ -323,7 +323,7 @@ You can override this by setting the `throwOnTransformError` argument to `true`. For example, if you have three parameters, _/param/a_, _/param/b_ and _/param/c_, but _/param/c_ is malformed: ```typescript hl_lines="23" title="Throwing TransformParameterError at first malformed parameter" ---8<-- "docs/snippets/parameters/transformPartialFailures.ts" +--8<-- "examples/snippets/parameters/transformPartialFailures.ts" ``` #### Auto-transform values on suffix @@ -336,7 +336,7 @@ You can do this with a single request by using `transform: 'auto'`. This will in `transform: 'auto'` feature is available across all providers, including the high level functions. ```typescript hl_lines="7" title="Deserializing parameter values based on their suffix" ---8<-- "docs/snippets/parameters/transformAuto.ts" +--8<-- "examples/snippets/parameters/transformAuto.ts" ``` For example, if you have three parameters: two with the following suffixes `.json` and `.binary` and one without any suffix: @@ -364,7 +364,7 @@ The two parameters with a suffix will be decoded, while the one without a suffix You can use a special `sdkOptions` object argument to pass any supported option directly to the underlying SDK method. ```typescript hl_lines="8 14" title="Specify a VersionId for a secret" ---8<-- "docs/snippets/parameters/sdkOptions.ts" +--8<-- "examples/snippets/parameters/sdkOptions.ts" ``` Here is the mapping between this utility's functions and methods and the underlying SDK: @@ -398,22 +398,22 @@ You can use the `awsSdkV3Client` parameter via any of the available [Provider Cl === "SSMProvider" ```typescript hl_lines="5 7" - --8<-- "docs/snippets/parameters/ssmProviderCustomClient.ts" + --8<-- "examples/snippets/parameters/ssmProviderCustomClient.ts" ``` === "SecretsProvider" ```typescript hl_lines="5 8" - --8<-- "docs/snippets/parameters/secretsProviderCustomClient.ts" + --8<-- "examples/snippets/parameters/secretsProviderCustomClient.ts" ``` === "AppConfigProvider" ```typescript hl_lines="5 8" - --8<-- "docs/snippets/parameters/appConfigProviderCustomClient.ts" + --8<-- "examples/snippets/parameters/appConfigProviderCustomClient.ts" ``` === "DynamoDBProvider" ```typescript hl_lines="5 7" - --8<-- "docs/snippets/parameters/dynamoDBProviderCustomClient.ts" + --8<-- "examples/snippets/parameters/dynamoDBProviderCustomClient.ts" ``` ### Customizing AWS SDK v3 configuration @@ -426,7 +426,7 @@ The **`clientConfig`** parameter enables you to pass in a custom [config object] When using VPC private endpoints, you can pass a custom client altogether. It's also useful for testing when injecting fake instances. ```typescript hl_lines="2 4-5" ---8<-- "docs/snippets/parameters/clientConfig.ts" +--8<-- "examples/snippets/parameters/clientConfig.ts" ``` ## Testing your code @@ -437,12 +437,12 @@ For unit testing your applications, you can mock the calls to the parameters uti === "handler.test.ts" ```typescript hl_lines="2 4-9 13 18" - --8<-- "docs/snippets/parameters/testingYourCodeFunctionsJestMock.ts" + --8<-- "examples/snippets/parameters/testingYourCodeFunctionsJestMock.ts" ``` === "handler.ts" ```typescript - --8<-- "docs/snippets/parameters/testingYourCodeFunctionsHandler.ts" + --8<-- "examples/snippets/parameters/testingYourCodeFunctionsHandler.ts" ``` With this pattern in place, you can customize the return values of the mocked function to test different scenarios without calling AWS APIs. @@ -451,24 +451,24 @@ A similar pattern can be applied also to any of the built-in provider classes - === "handler.test.ts" ```typescript hl_lines="2 5 8 19 26-27" - --8<-- "docs/snippets/parameters/testingYourCodeProvidersJestMock.ts" + --8<-- "examples/snippets/parameters/testingYourCodeProvidersJestMock.ts" ``` === "handler.ts" ```typescript - --8<-- "docs/snippets/parameters/testingYourCodeProvidersHandler.ts" + --8<-- "examples/snippets/parameters/testingYourCodeProvidersHandler.ts" ``` For when you want to mock the AWS SDK v3 client directly, we recommend using the [`aws-sdk-client-mock`](https://www.npmjs.com/package/aws-sdk-client-mock) and [`aws-sdk-client-mock-jest`](https://www.npmjs.com/package/aws-sdk-client-mock-jest) libraries. This is useful when you want to test how your code behaves when the AWS SDK v3 client throws an error or a specific response. === "handler.test.ts" ```typescript hl_lines="2-8 11 14 18 23-30" - --8<-- "docs/snippets/parameters/testingYourCodeClientJestMock.ts" + --8<-- "examples/snippets/parameters/testingYourCodeClientJestMock.ts" ``` === "handler.ts" ```typescript - --8<-- "docs/snippets/parameters/testingYourCodeClientHandler.ts" + --8<-- "examples/snippets/parameters/testingYourCodeClientHandler.ts" ``` ### Clearing cache @@ -479,5 +479,5 @@ Within your tests, you can use `clearCache` method available in [every provider] === "handler.test.ts" ```typescript hl_lines="1 9" - --8<-- "docs/snippets/parameters/testingYourCodeClearCache.ts" + --8<-- "examples/snippets/parameters/testingYourCodeClearCache.ts" ``` diff --git a/docs/utilities/parser.md b/docs/utilities/parser.md index 21281db6d6..bc22b26932 100644 --- a/docs/utilities/parser.md +++ b/docs/utilities/parser.md @@ -6,9 +6,7 @@ status: new -This utility provides data validation and parsing using [Zod](https://zod.dev){target="_blank"}. - -Zod is a TypeScript-first schema declaration and validation library. +This utility provides data validation and parsing using [Zod](https://zod.dev){target="_blank"}, a TypeScript-first schema declaration and validation library. ## Key features @@ -33,7 +31,7 @@ This utility supports Zod v3.x and above. You can define your schema using Zod: ```typescript title="schema.ts" ---8<-- "docs/snippets/parser/schema.ts" +--8<-- "examples/snippets/parser/schema.ts" ``` This is a schema for `Order` object using Zod. @@ -50,12 +48,12 @@ Both are also able to parse either an object or JSON string as an input. === "Middy middleware" ```typescript hl_lines="34" - --8<-- "docs/snippets/parser/middy.ts" + --8<-- "examples/snippets/parser/middy.ts" ``` === "Decorator" ```typescript hl_lines="25" - --8<-- "docs/snippets/parser/decorator.ts" + --8<-- "examples/snippets/parser/decorator.ts" ``` ## Built-in schemas @@ -95,7 +93,7 @@ You can extend every built-in schema to include your own schema, and yet have al === "handler.ts" ```typescript hl_lines="23-25 30 34" - --8<-- "docs/snippets/parser/extend.ts" + --8<-- "examples/snippets/parser/extend.ts" ``` 1. Extend built-in `EventBridgeSchema` with your own detail schema @@ -105,7 +103,7 @@ You can extend every built-in schema to include your own schema, and yet have al === "Example payload" ```json - --8<-- "docs/snippets/parser/examplePayload.json" + --8<-- "examples/snippets/parser/examplePayload.json" ``` ## Envelopes @@ -122,12 +120,12 @@ Here's an example of parsing a custom schema in an event coming from EventBridge === "Middy middleware" ```typescript hl_lines="5 36" - --8<-- "docs/snippets/parser/envelopeMiddy.ts" + --8<-- "examples/snippets/parser/envelopeMiddy.ts" ``` === "Decorator" ```typescript hl_lines="5 26 30" - --8<-- "docs/snippets/parser/envelopeDecorator.ts" + --8<-- "examples/snippets/parser/envelopeDecorator.ts" ``` 1. Pass `eventBridgeEnvelope` to `parser` decorator @@ -172,7 +170,7 @@ If the parsing is successful, the `data` field will contain the parsed event, ot === "Middy middleware" ```typescript hl_lines="32 35 38 39 44" - --8<-- "docs/snippets/parser/safeParseMiddy.ts" + --8<-- "examples/snippets/parser/safeParseMiddy.ts" ``` 1. Use `safeParse` option to parse the event without throwing an error @@ -183,7 +181,7 @@ If the parsing is successful, the `data` field will contain the parsed event, ot === "Decorator" ```typescript hl_lines="29 35 37 40 41" - --8<-- "docs/snippets/parser/safeParseDecorator.ts" + --8<-- "examples/snippets/parser/safeParseDecorator.ts" ``` 1. Use `safeParse` option to parse the event without throwing an error @@ -198,7 +196,7 @@ You can use built-in envelopes and schemas to parse the incoming events manually === "Manual parse" ```typescript hl_lines="28 31" - --8<-- "docs/snippets/parser/manual.ts" + --8<-- "examples/snippets/parser/manual.ts" ``` 1. Use `EventBridgeSchema` to parse the event, the `details` fields will be parsed as a generic record. @@ -206,7 +204,7 @@ You can use built-in envelopes and schemas to parse the incoming events manually === "Manual safeParse" ```typescript hl_lines="27 31" - --8<-- "docs/snippets/parser/manualSafeParse.ts" + --8<-- "examples/snippets/parser/manualSafeParse.ts" ``` 1. Use `safeParse` option to parse the event without throwing an error @@ -219,7 +217,7 @@ For example, you can use `refine` to validate a field or a combination of fields === "Custom validation" ```typescript hl_lines="13 18" - --8<-- "docs/snippets/parser/refine.ts" + --8<-- "examples/snippets/parser/refine.ts" ``` 1. validate a single field @@ -235,7 +233,7 @@ Use `z.infer` to extract the type of the schema, so you can use types during dev === "Types" ```typescript hl_lines="22 25 30" - --8<-- "docs/snippets/parser/types.ts" + --8<-- "examples/snippets/parser/types.ts" ``` 1. Use `z.infer` to extract the type of the schema, also works for nested schemas diff --git a/docs/snippets/CHANGELOG.md b/examples/snippets/CHANGELOG.md similarity index 100% rename from docs/snippets/CHANGELOG.md rename to examples/snippets/CHANGELOG.md diff --git a/docs/snippets/batch/accessLambdaContext.ts b/examples/snippets/batch/accessLambdaContext.ts similarity index 100% rename from docs/snippets/batch/accessLambdaContext.ts rename to examples/snippets/batch/accessLambdaContext.ts diff --git a/docs/snippets/batch/accessProcessedMessages.ts b/examples/snippets/batch/accessProcessedMessages.ts similarity index 100% rename from docs/snippets/batch/accessProcessedMessages.ts rename to examples/snippets/batch/accessProcessedMessages.ts diff --git a/docs/snippets/batch/advancedTracingRecordHandler.ts b/examples/snippets/batch/advancedTracingRecordHandler.ts similarity index 100% rename from docs/snippets/batch/advancedTracingRecordHandler.ts rename to examples/snippets/batch/advancedTracingRecordHandler.ts diff --git a/docs/snippets/batch/customPartialProcessor.ts b/examples/snippets/batch/customPartialProcessor.ts similarity index 100% rename from docs/snippets/batch/customPartialProcessor.ts rename to examples/snippets/batch/customPartialProcessor.ts diff --git a/docs/snippets/batch/extendingFailure.ts b/examples/snippets/batch/extendingFailure.ts similarity index 100% rename from docs/snippets/batch/extendingFailure.ts rename to examples/snippets/batch/extendingFailure.ts diff --git a/docs/snippets/batch/gettingStartedDynamoDBStreams.ts b/examples/snippets/batch/gettingStartedDynamoDBStreams.ts similarity index 100% rename from docs/snippets/batch/gettingStartedDynamoDBStreams.ts rename to examples/snippets/batch/gettingStartedDynamoDBStreams.ts diff --git a/docs/snippets/batch/gettingStartedErrorHandling.ts b/examples/snippets/batch/gettingStartedErrorHandling.ts similarity index 100% rename from docs/snippets/batch/gettingStartedErrorHandling.ts rename to examples/snippets/batch/gettingStartedErrorHandling.ts diff --git a/docs/snippets/batch/gettingStartedKinesis.ts b/examples/snippets/batch/gettingStartedKinesis.ts similarity index 100% rename from docs/snippets/batch/gettingStartedKinesis.ts rename to examples/snippets/batch/gettingStartedKinesis.ts diff --git a/docs/snippets/batch/gettingStartedSQS.ts b/examples/snippets/batch/gettingStartedSQS.ts similarity index 100% rename from docs/snippets/batch/gettingStartedSQS.ts rename to examples/snippets/batch/gettingStartedSQS.ts diff --git a/docs/snippets/batch/gettingStartedSQSFifo.ts b/examples/snippets/batch/gettingStartedSQSFifo.ts similarity index 100% rename from docs/snippets/batch/gettingStartedSQSFifo.ts rename to examples/snippets/batch/gettingStartedSQSFifo.ts diff --git a/docs/snippets/batch/samples/sampleDynamoDBStreamsEvent.json b/examples/snippets/batch/samples/sampleDynamoDBStreamsEvent.json similarity index 100% rename from docs/snippets/batch/samples/sampleDynamoDBStreamsEvent.json rename to examples/snippets/batch/samples/sampleDynamoDBStreamsEvent.json diff --git a/docs/snippets/batch/samples/sampleDynamoDBStreamsResponse.json b/examples/snippets/batch/samples/sampleDynamoDBStreamsResponse.json similarity index 100% rename from docs/snippets/batch/samples/sampleDynamoDBStreamsResponse.json rename to examples/snippets/batch/samples/sampleDynamoDBStreamsResponse.json diff --git a/docs/snippets/batch/samples/sampleKinesisEvent.json b/examples/snippets/batch/samples/sampleKinesisEvent.json similarity index 100% rename from docs/snippets/batch/samples/sampleKinesisEvent.json rename to examples/snippets/batch/samples/sampleKinesisEvent.json diff --git a/docs/snippets/batch/samples/sampleKinesisResponse.json b/examples/snippets/batch/samples/sampleKinesisResponse.json similarity index 100% rename from docs/snippets/batch/samples/sampleKinesisResponse.json rename to examples/snippets/batch/samples/sampleKinesisResponse.json diff --git a/docs/snippets/batch/samples/sampleSQSEvent.json b/examples/snippets/batch/samples/sampleSQSEvent.json similarity index 100% rename from docs/snippets/batch/samples/sampleSQSEvent.json rename to examples/snippets/batch/samples/sampleSQSEvent.json diff --git a/docs/snippets/batch/samples/sampleSQSResponse.json b/examples/snippets/batch/samples/sampleSQSResponse.json similarity index 100% rename from docs/snippets/batch/samples/sampleSQSResponse.json rename to examples/snippets/batch/samples/sampleSQSResponse.json diff --git a/docs/snippets/batch/templates/sam/dynamodb.yaml b/examples/snippets/batch/templates/sam/dynamodb.yaml similarity index 100% rename from docs/snippets/batch/templates/sam/dynamodb.yaml rename to examples/snippets/batch/templates/sam/dynamodb.yaml diff --git a/docs/snippets/batch/templates/sam/kinesis.yaml b/examples/snippets/batch/templates/sam/kinesis.yaml similarity index 100% rename from docs/snippets/batch/templates/sam/kinesis.yaml rename to examples/snippets/batch/templates/sam/kinesis.yaml diff --git a/docs/snippets/batch/templates/sam/sqs.yaml b/examples/snippets/batch/templates/sam/sqs.yaml similarity index 100% rename from docs/snippets/batch/templates/sam/sqs.yaml rename to examples/snippets/batch/templates/sam/sqs.yaml diff --git a/docs/snippets/batch/testingYourCode.ts b/examples/snippets/batch/testingYourCode.ts similarity index 100% rename from docs/snippets/batch/testingYourCode.ts rename to examples/snippets/batch/testingYourCode.ts diff --git a/docs/snippets/idempotency/advancedBringYourOwnPersistenceLayer.ts b/examples/snippets/idempotency/advancedBringYourOwnPersistenceLayer.ts similarity index 100% rename from docs/snippets/idempotency/advancedBringYourOwnPersistenceLayer.ts rename to examples/snippets/idempotency/advancedBringYourOwnPersistenceLayer.ts diff --git a/docs/snippets/idempotency/advancedBringYourOwnPersistenceLayerProvider.ts b/examples/snippets/idempotency/advancedBringYourOwnPersistenceLayerProvider.ts similarity index 94% rename from docs/snippets/idempotency/advancedBringYourOwnPersistenceLayerProvider.ts rename to examples/snippets/idempotency/advancedBringYourOwnPersistenceLayerProvider.ts index 3dedecf864..f639b63c3f 100644 --- a/docs/snippets/idempotency/advancedBringYourOwnPersistenceLayerProvider.ts +++ b/examples/snippets/idempotency/advancedBringYourOwnPersistenceLayerProvider.ts @@ -1,4 +1,4 @@ -import type { ProviderItem } from './types'; +import type { ProviderItem } from './types.js'; /** * This is a mock implementation of an SDK client for a generic key-value store. diff --git a/docs/snippets/idempotency/advancedBringYourOwnPersistenceLayerUsage.ts b/examples/snippets/idempotency/advancedBringYourOwnPersistenceLayerUsage.ts similarity index 99% rename from docs/snippets/idempotency/advancedBringYourOwnPersistenceLayerUsage.ts rename to examples/snippets/idempotency/advancedBringYourOwnPersistenceLayerUsage.ts index 2e8b5fa29e..59a5fa7a31 100644 --- a/docs/snippets/idempotency/advancedBringYourOwnPersistenceLayerUsage.ts +++ b/examples/snippets/idempotency/advancedBringYourOwnPersistenceLayerUsage.ts @@ -5,7 +5,7 @@ import { IdempotencyConfig, makeIdempotent, } from '@aws-lambda-powertools/idempotency'; -import type { Request, Response, SubscriptionResult } from './types'; +import type { Request, Response, SubscriptionResult } from './types.js'; const persistenceStore = new CustomPersistenceLayer({ collectionName: 'powertools', diff --git a/docs/snippets/idempotency/customizePersistenceLayer.ts b/examples/snippets/idempotency/customizePersistenceLayer.ts similarity index 94% rename from docs/snippets/idempotency/customizePersistenceLayer.ts rename to examples/snippets/idempotency/customizePersistenceLayer.ts index 138da79b9c..658fd5e562 100644 --- a/docs/snippets/idempotency/customizePersistenceLayer.ts +++ b/examples/snippets/idempotency/customizePersistenceLayer.ts @@ -2,7 +2,7 @@ import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middle 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'; +import type { Request, Response } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/idempotentDecoratorBase.ts b/examples/snippets/idempotency/idempotentDecoratorBase.ts similarity index 94% rename from docs/snippets/idempotency/idempotentDecoratorBase.ts rename to examples/snippets/idempotency/idempotentDecoratorBase.ts index 409a34647f..b486fc6db7 100644 --- a/docs/snippets/idempotency/idempotentDecoratorBase.ts +++ b/examples/snippets/idempotency/idempotentDecoratorBase.ts @@ -5,7 +5,7 @@ import { idempotent, } from '@aws-lambda-powertools/idempotency'; import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; -import type { Request, Response } from './types'; +import type { Request, Response } from './types.js'; const dynamoDBPersistenceLayer = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/makeHandlerIdempotent.ts b/examples/snippets/idempotency/makeHandlerIdempotent.ts similarity index 99% rename from docs/snippets/idempotency/makeHandlerIdempotent.ts rename to examples/snippets/idempotency/makeHandlerIdempotent.ts index 3989b15cd6..3ec8f0ebfb 100644 --- a/docs/snippets/idempotency/makeHandlerIdempotent.ts +++ b/examples/snippets/idempotency/makeHandlerIdempotent.ts @@ -3,7 +3,7 @@ import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middle 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'; +import type { Request, Response, SubscriptionResult } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/makeIdempotentAnyFunction.ts b/examples/snippets/idempotency/makeIdempotentAnyFunction.ts similarity index 99% rename from docs/snippets/idempotency/makeIdempotentAnyFunction.ts rename to examples/snippets/idempotency/makeIdempotentAnyFunction.ts index ead0ca408e..873952ea84 100644 --- a/docs/snippets/idempotency/makeIdempotentAnyFunction.ts +++ b/examples/snippets/idempotency/makeIdempotentAnyFunction.ts @@ -5,7 +5,7 @@ import { } 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'; +import type { Request, Response, SubscriptionResult } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/makeIdempotentBase.ts b/examples/snippets/idempotency/makeIdempotentBase.ts similarity index 99% rename from docs/snippets/idempotency/makeIdempotentBase.ts rename to examples/snippets/idempotency/makeIdempotentBase.ts index 857fa8dfab..1aa8ae451a 100644 --- a/docs/snippets/idempotency/makeIdempotentBase.ts +++ b/examples/snippets/idempotency/makeIdempotentBase.ts @@ -2,7 +2,7 @@ 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'; +import type { Request, Response, SubscriptionResult } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/makeIdempotentJmes.ts b/examples/snippets/idempotency/makeIdempotentJmes.ts similarity index 99% rename from docs/snippets/idempotency/makeIdempotentJmes.ts rename to examples/snippets/idempotency/makeIdempotentJmes.ts index ddad91ad45..9688bbf79a 100644 --- a/docs/snippets/idempotency/makeIdempotentJmes.ts +++ b/examples/snippets/idempotency/makeIdempotentJmes.ts @@ -5,7 +5,7 @@ import { } 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'; +import type { Request, Response, SubscriptionResult } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/makeIdempotentLambdaContext.ts b/examples/snippets/idempotency/makeIdempotentLambdaContext.ts similarity index 99% rename from docs/snippets/idempotency/makeIdempotentLambdaContext.ts rename to examples/snippets/idempotency/makeIdempotentLambdaContext.ts index d90ee17eb1..da47482e22 100644 --- a/docs/snippets/idempotency/makeIdempotentLambdaContext.ts +++ b/examples/snippets/idempotency/makeIdempotentLambdaContext.ts @@ -5,7 +5,7 @@ import { } 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'; +import type { Request, Response, SubscriptionResult } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/requiredIdempotencyKey.ts b/examples/snippets/idempotency/requiredIdempotencyKey.ts similarity index 100% rename from docs/snippets/idempotency/requiredIdempotencyKey.ts rename to examples/snippets/idempotency/requiredIdempotencyKey.ts diff --git a/docs/snippets/idempotency/samples/makeIdempotentJmes.json b/examples/snippets/idempotency/samples/makeIdempotentJmes.json similarity index 100% rename from docs/snippets/idempotency/samples/makeIdempotentJmes.json rename to examples/snippets/idempotency/samples/makeIdempotentJmes.json diff --git a/docs/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeyError.json b/examples/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeyError.json similarity index 100% rename from docs/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeyError.json rename to examples/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeyError.json diff --git a/docs/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeySuccess.json b/examples/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeySuccess.json similarity index 100% rename from docs/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeySuccess.json rename to examples/snippets/idempotency/samples/workingWIthIdempotencyRequiredKeySuccess.json diff --git a/docs/snippets/idempotency/samples/workingWithBatch.json b/examples/snippets/idempotency/samples/workingWithBatch.json similarity index 100% rename from docs/snippets/idempotency/samples/workingWithBatch.json rename to examples/snippets/idempotency/samples/workingWithBatch.json diff --git a/docs/snippets/idempotency/templates/tableCdk.ts b/examples/snippets/idempotency/templates/tableCdk.ts similarity index 100% rename from docs/snippets/idempotency/templates/tableCdk.ts rename to examples/snippets/idempotency/templates/tableCdk.ts diff --git a/docs/snippets/idempotency/templates/tableSam.yaml b/examples/snippets/idempotency/templates/tableSam.yaml similarity index 100% rename from docs/snippets/idempotency/templates/tableSam.yaml rename to examples/snippets/idempotency/templates/tableSam.yaml diff --git a/docs/snippets/idempotency/templates/tableTerraform.tf b/examples/snippets/idempotency/templates/tableTerraform.tf similarity index 100% rename from docs/snippets/idempotency/templates/tableTerraform.tf rename to examples/snippets/idempotency/templates/tableTerraform.tf diff --git a/docs/snippets/idempotency/types.ts b/examples/snippets/idempotency/types.ts similarity index 100% rename from docs/snippets/idempotency/types.ts rename to examples/snippets/idempotency/types.ts diff --git a/docs/snippets/idempotency/workingWithBatch.ts b/examples/snippets/idempotency/workingWithBatch.ts similarity index 100% rename from docs/snippets/idempotency/workingWithBatch.ts rename to examples/snippets/idempotency/workingWithBatch.ts diff --git a/docs/snippets/idempotency/workingWithCompositeKey.ts b/examples/snippets/idempotency/workingWithCompositeKey.ts similarity index 93% rename from docs/snippets/idempotency/workingWithCompositeKey.ts rename to examples/snippets/idempotency/workingWithCompositeKey.ts index 8b13d122c7..d58c8689ca 100644 --- a/docs/snippets/idempotency/workingWithCompositeKey.ts +++ b/examples/snippets/idempotency/workingWithCompositeKey.ts @@ -2,7 +2,7 @@ import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middle 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'; +import type { Request, Response } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/workingWithCustomClient.ts b/examples/snippets/idempotency/workingWithCustomClient.ts similarity index 94% rename from docs/snippets/idempotency/workingWithCustomClient.ts rename to examples/snippets/idempotency/workingWithCustomClient.ts index 1577912f10..8f3720d46e 100644 --- a/docs/snippets/idempotency/workingWithCustomClient.ts +++ b/examples/snippets/idempotency/workingWithCustomClient.ts @@ -2,7 +2,7 @@ import { makeIdempotent } from '@aws-lambda-powertools/idempotency'; import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; import type { Context } from 'aws-lambda'; -import type { Request, Response } from './types'; +import type { Request, Response } from './types.js'; const customDynamoDBClient = new DynamoDBClient({ endpoint: 'http://localhost:8000', diff --git a/docs/snippets/idempotency/workingWithCustomConfig.ts b/examples/snippets/idempotency/workingWithCustomConfig.ts similarity index 93% rename from docs/snippets/idempotency/workingWithCustomConfig.ts rename to examples/snippets/idempotency/workingWithCustomConfig.ts index 6507a1a32c..4138825d91 100644 --- a/docs/snippets/idempotency/workingWithCustomConfig.ts +++ b/examples/snippets/idempotency/workingWithCustomConfig.ts @@ -1,7 +1,7 @@ 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 } from './types'; +import type { Request, Response } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/workingWithExceptions.ts b/examples/snippets/idempotency/workingWithExceptions.ts similarity index 99% rename from docs/snippets/idempotency/workingWithExceptions.ts rename to examples/snippets/idempotency/workingWithExceptions.ts index 60d957d893..badf618958 100644 --- a/docs/snippets/idempotency/workingWithExceptions.ts +++ b/examples/snippets/idempotency/workingWithExceptions.ts @@ -5,7 +5,7 @@ import { } 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'; +import type { Request, Response, SubscriptionResult } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/workingWithIdempotencyRequiredKey.ts b/examples/snippets/idempotency/workingWithIdempotencyRequiredKey.ts similarity index 93% rename from docs/snippets/idempotency/workingWithIdempotencyRequiredKey.ts rename to examples/snippets/idempotency/workingWithIdempotencyRequiredKey.ts index 9642e6a630..ffdb58d7dd 100644 --- a/docs/snippets/idempotency/workingWithIdempotencyRequiredKey.ts +++ b/examples/snippets/idempotency/workingWithIdempotencyRequiredKey.ts @@ -4,7 +4,7 @@ import { } from '@aws-lambda-powertools/idempotency'; import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; import type { Context } from 'aws-lambda'; -import type { Request, Response } from './types'; +import type { Request, Response } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/workingWithLocalCache.ts b/examples/snippets/idempotency/workingWithLocalCache.ts similarity index 94% rename from docs/snippets/idempotency/workingWithLocalCache.ts rename to examples/snippets/idempotency/workingWithLocalCache.ts index 8570f3f055..aa0cebd31c 100644 --- a/docs/snippets/idempotency/workingWithLocalCache.ts +++ b/examples/snippets/idempotency/workingWithLocalCache.ts @@ -3,7 +3,7 @@ import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency/middle 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'; +import type { Request, Response } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/workingWithPayloadValidation.ts b/examples/snippets/idempotency/workingWithPayloadValidation.ts similarity index 99% rename from docs/snippets/idempotency/workingWithPayloadValidation.ts rename to examples/snippets/idempotency/workingWithPayloadValidation.ts index eb582656a0..d253e5c5ee 100644 --- a/docs/snippets/idempotency/workingWithPayloadValidation.ts +++ b/examples/snippets/idempotency/workingWithPayloadValidation.ts @@ -5,7 +5,7 @@ import { } 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'; +import type { Request, Response, SubscriptionResult } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/idempotency/workingWithRecordExpiration.ts b/examples/snippets/idempotency/workingWithRecordExpiration.ts similarity index 93% rename from docs/snippets/idempotency/workingWithRecordExpiration.ts rename to examples/snippets/idempotency/workingWithRecordExpiration.ts index 39fa7594eb..77e2296147 100644 --- a/docs/snippets/idempotency/workingWithRecordExpiration.ts +++ b/examples/snippets/idempotency/workingWithRecordExpiration.ts @@ -4,7 +4,7 @@ import { } from '@aws-lambda-powertools/idempotency'; import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb'; import type { Context } from 'aws-lambda'; -import type { Request, Response } from './types'; +import type { Request, Response } from './types.js'; const persistenceStore = new DynamoDBPersistenceLayer({ tableName: 'idempotencyTableName', diff --git a/docs/snippets/jmespath/extractDataFromBuiltinEnvelope.json b/examples/snippets/jmespath/extractDataFromBuiltinEnvelope.json similarity index 100% rename from docs/snippets/jmespath/extractDataFromBuiltinEnvelope.json rename to examples/snippets/jmespath/extractDataFromBuiltinEnvelope.json diff --git a/docs/snippets/jmespath/extractDataFromBuiltinEnvelope.ts b/examples/snippets/jmespath/extractDataFromBuiltinEnvelope.ts similarity index 100% rename from docs/snippets/jmespath/extractDataFromBuiltinEnvelope.ts rename to examples/snippets/jmespath/extractDataFromBuiltinEnvelope.ts diff --git a/docs/snippets/jmespath/extractDataFromEnvelope.json b/examples/snippets/jmespath/extractDataFromEnvelope.json similarity index 100% rename from docs/snippets/jmespath/extractDataFromEnvelope.json rename to examples/snippets/jmespath/extractDataFromEnvelope.json diff --git a/docs/snippets/jmespath/extractDataFromEnvelope.ts b/examples/snippets/jmespath/extractDataFromEnvelope.ts similarity index 100% rename from docs/snippets/jmespath/extractDataFromEnvelope.ts rename to examples/snippets/jmespath/extractDataFromEnvelope.ts diff --git a/docs/snippets/jmespath/powertoolsBase64GzipJmespath.ts b/examples/snippets/jmespath/powertoolsBase64GzipJmespath.ts similarity index 100% rename from docs/snippets/jmespath/powertoolsBase64GzipJmespath.ts rename to examples/snippets/jmespath/powertoolsBase64GzipJmespath.ts diff --git a/docs/snippets/jmespath/powertoolsBase64GzipJmespathPayload.json b/examples/snippets/jmespath/powertoolsBase64GzipJmespathPayload.json similarity index 100% rename from docs/snippets/jmespath/powertoolsBase64GzipJmespathPayload.json rename to examples/snippets/jmespath/powertoolsBase64GzipJmespathPayload.json diff --git a/docs/snippets/jmespath/powertoolsBase64Jmespath.ts b/examples/snippets/jmespath/powertoolsBase64Jmespath.ts similarity index 100% rename from docs/snippets/jmespath/powertoolsBase64Jmespath.ts rename to examples/snippets/jmespath/powertoolsBase64Jmespath.ts diff --git a/docs/snippets/jmespath/powertoolsBase64JmespathPayload.json b/examples/snippets/jmespath/powertoolsBase64JmespathPayload.json similarity index 100% rename from docs/snippets/jmespath/powertoolsBase64JmespathPayload.json rename to examples/snippets/jmespath/powertoolsBase64JmespathPayload.json diff --git a/docs/snippets/jmespath/powertoolsCustomFunction.json b/examples/snippets/jmespath/powertoolsCustomFunction.json similarity index 100% rename from docs/snippets/jmespath/powertoolsCustomFunction.json rename to examples/snippets/jmespath/powertoolsCustomFunction.json diff --git a/docs/snippets/jmespath/powertoolsCustomFunction.ts b/examples/snippets/jmespath/powertoolsCustomFunction.ts similarity index 100% rename from docs/snippets/jmespath/powertoolsCustomFunction.ts rename to examples/snippets/jmespath/powertoolsCustomFunction.ts diff --git a/docs/snippets/jmespath/powertoolsJsonIdempotencyJmespath.json b/examples/snippets/jmespath/powertoolsJsonIdempotencyJmespath.json similarity index 100% rename from docs/snippets/jmespath/powertoolsJsonIdempotencyJmespath.json rename to examples/snippets/jmespath/powertoolsJsonIdempotencyJmespath.json diff --git a/docs/snippets/jmespath/powertoolsJsonIdempotencyJmespath.ts b/examples/snippets/jmespath/powertoolsJsonIdempotencyJmespath.ts similarity index 100% rename from docs/snippets/jmespath/powertoolsJsonIdempotencyJmespath.ts rename to examples/snippets/jmespath/powertoolsJsonIdempotencyJmespath.ts diff --git a/docs/snippets/logger/appendKeys.ts b/examples/snippets/logger/appendKeys.ts similarity index 72% rename from docs/snippets/logger/appendKeys.ts rename to examples/snippets/logger/appendKeys.ts index ed779dab77..e99fc20cb2 100644 --- a/docs/snippets/logger/appendKeys.ts +++ b/examples/snippets/logger/appendKeys.ts @@ -13,17 +13,6 @@ const logger = new Logger({ }, }); -// OR add persistent log keys to an existing Logger instance with the appendKeys method: -// logger.appendKeys({ -// aws_account_id: '123456789012', -// aws_region: 'eu-west-1', -// logger: { -// name: '@aws-lambda-powertools/logger', -// version: '0.0.1', -// }, -// extra_key: "some-value" -// }); - export const handler = async ( _event: unknown, _context: unknown diff --git a/docs/snippets/logger/basicUsage.ts b/examples/snippets/logger/basicUsage.ts similarity index 100% rename from docs/snippets/logger/basicUsage.ts rename to examples/snippets/logger/basicUsage.ts diff --git a/docs/snippets/logger/bringYourOwnFormatterClass.ts b/examples/snippets/logger/bringYourOwnFormatterClass.ts similarity index 100% rename from docs/snippets/logger/bringYourOwnFormatterClass.ts rename to examples/snippets/logger/bringYourOwnFormatterClass.ts diff --git a/docs/snippets/logger/bringYourOwnFormatterHandler.ts b/examples/snippets/logger/bringYourOwnFormatterHandler.ts similarity index 100% rename from docs/snippets/logger/bringYourOwnFormatterHandler.ts rename to examples/snippets/logger/bringYourOwnFormatterHandler.ts diff --git a/docs/snippets/logger/clearStateDecorator.ts b/examples/snippets/logger/clearStateDecorator.ts similarity index 100% rename from docs/snippets/logger/clearStateDecorator.ts rename to examples/snippets/logger/clearStateDecorator.ts diff --git a/docs/snippets/logger/clearStateMiddy.ts b/examples/snippets/logger/clearStateMiddy.ts similarity index 100% rename from docs/snippets/logger/clearStateMiddy.ts rename to examples/snippets/logger/clearStateMiddy.ts diff --git a/docs/snippets/logger/createChild.ts b/examples/snippets/logger/createChild.ts similarity index 100% rename from docs/snippets/logger/createChild.ts rename to examples/snippets/logger/createChild.ts diff --git a/docs/snippets/logger/decorator.ts b/examples/snippets/logger/decorator.ts similarity index 100% rename from docs/snippets/logger/decorator.ts rename to examples/snippets/logger/decorator.ts diff --git a/docs/snippets/logger/eventDecorator.ts b/examples/snippets/logger/eventDecorator.ts similarity index 100% rename from docs/snippets/logger/eventDecorator.ts rename to examples/snippets/logger/eventDecorator.ts diff --git a/docs/snippets/logger/eventMiddy.ts b/examples/snippets/logger/eventMiddy.ts similarity index 100% rename from docs/snippets/logger/eventMiddy.ts rename to examples/snippets/logger/eventMiddy.ts diff --git a/docs/snippets/logger/extraData.ts b/examples/snippets/logger/extraData.ts similarity index 100% rename from docs/snippets/logger/extraData.ts rename to examples/snippets/logger/extraData.ts diff --git a/docs/snippets/logger/logError.ts b/examples/snippets/logger/logError.ts similarity index 100% rename from docs/snippets/logger/logError.ts rename to examples/snippets/logger/logError.ts diff --git a/docs/snippets/logger/logLevel.ts b/examples/snippets/logger/logLevel.ts similarity index 85% rename from docs/snippets/logger/logLevel.ts rename to examples/snippets/logger/logLevel.ts index 5a7ceacb65..7afbdb4e92 100644 --- a/docs/snippets/logger/logLevel.ts +++ b/examples/snippets/logger/logLevel.ts @@ -4,4 +4,3 @@ const logger = new Logger(); logger.getLevelName(); // returns "INFO" logger.setLogLevel('DEBUG'); -logger.level; // returns 8 diff --git a/docs/snippets/logger/logSampling.ts b/examples/snippets/logger/logSampling.ts similarity index 100% rename from docs/snippets/logger/logSampling.ts rename to examples/snippets/logger/logSampling.ts diff --git a/docs/snippets/logger/manual.ts b/examples/snippets/logger/manual.ts similarity index 100% rename from docs/snippets/logger/manual.ts rename to examples/snippets/logger/manual.ts diff --git a/docs/snippets/logger/middy.ts b/examples/snippets/logger/middy.ts similarity index 100% rename from docs/snippets/logger/middy.ts rename to examples/snippets/logger/middy.ts diff --git a/docs/snippets/logger/sam.ts b/examples/snippets/logger/sam.ts similarity index 100% rename from docs/snippets/logger/sam.ts rename to examples/snippets/logger/sam.ts diff --git a/docs/snippets/logger/unitTesting.ts b/examples/snippets/logger/unitTesting.ts similarity index 100% rename from docs/snippets/logger/unitTesting.ts rename to examples/snippets/logger/unitTesting.ts diff --git a/docs/snippets/metrics/addHighResolutionMetric.ts b/examples/snippets/metrics/addHighResolutionMetric.ts similarity index 100% rename from docs/snippets/metrics/addHighResolutionMetric.ts rename to examples/snippets/metrics/addHighResolutionMetric.ts diff --git a/docs/snippets/metrics/addMetadata.ts b/examples/snippets/metrics/addMetadata.ts similarity index 100% rename from docs/snippets/metrics/addMetadata.ts rename to examples/snippets/metrics/addMetadata.ts diff --git a/docs/snippets/metrics/basicUsage.ts b/examples/snippets/metrics/basicUsage.ts similarity index 100% rename from docs/snippets/metrics/basicUsage.ts rename to examples/snippets/metrics/basicUsage.ts diff --git a/docs/snippets/metrics/captureColdStartMetricDecorator.ts b/examples/snippets/metrics/captureColdStartMetricDecorator.ts similarity index 100% rename from docs/snippets/metrics/captureColdStartMetricDecorator.ts rename to examples/snippets/metrics/captureColdStartMetricDecorator.ts diff --git a/docs/snippets/metrics/captureColdStartMetricMiddy.ts b/examples/snippets/metrics/captureColdStartMetricMiddy.ts similarity index 100% rename from docs/snippets/metrics/captureColdStartMetricMiddy.ts rename to examples/snippets/metrics/captureColdStartMetricMiddy.ts diff --git a/docs/snippets/metrics/createMetrics.ts b/examples/snippets/metrics/createMetrics.ts similarity index 100% rename from docs/snippets/metrics/createMetrics.ts rename to examples/snippets/metrics/createMetrics.ts diff --git a/docs/snippets/metrics/customDimensions.ts b/examples/snippets/metrics/customDimensions.ts similarity index 100% rename from docs/snippets/metrics/customDimensions.ts rename to examples/snippets/metrics/customDimensions.ts diff --git a/docs/snippets/metrics/decorator.ts b/examples/snippets/metrics/decorator.ts similarity index 100% rename from docs/snippets/metrics/decorator.ts rename to examples/snippets/metrics/decorator.ts diff --git a/docs/snippets/metrics/defaultDimensions.ts b/examples/snippets/metrics/defaultDimensions.ts similarity index 100% rename from docs/snippets/metrics/defaultDimensions.ts rename to examples/snippets/metrics/defaultDimensions.ts diff --git a/docs/snippets/metrics/defaultDimensionsDecorator.ts b/examples/snippets/metrics/defaultDimensionsDecorator.ts similarity index 100% rename from docs/snippets/metrics/defaultDimensionsDecorator.ts rename to examples/snippets/metrics/defaultDimensionsDecorator.ts diff --git a/docs/snippets/metrics/defaultDimensionsMiddy.ts b/examples/snippets/metrics/defaultDimensionsMiddy.ts similarity index 100% rename from docs/snippets/metrics/defaultDimensionsMiddy.ts rename to examples/snippets/metrics/defaultDimensionsMiddy.ts diff --git a/docs/snippets/metrics/manual.ts b/examples/snippets/metrics/manual.ts similarity index 100% rename from docs/snippets/metrics/manual.ts rename to examples/snippets/metrics/manual.ts diff --git a/docs/snippets/metrics/middy.ts b/examples/snippets/metrics/middy.ts similarity index 100% rename from docs/snippets/metrics/middy.ts rename to examples/snippets/metrics/middy.ts diff --git a/docs/snippets/metrics/multiValueMetrics.ts b/examples/snippets/metrics/multiValueMetrics.ts similarity index 100% rename from docs/snippets/metrics/multiValueMetrics.ts rename to examples/snippets/metrics/multiValueMetrics.ts diff --git a/docs/snippets/metrics/sam.ts b/examples/snippets/metrics/sam.ts similarity index 100% rename from docs/snippets/metrics/sam.ts rename to examples/snippets/metrics/sam.ts diff --git a/docs/snippets/metrics/setDefaultDimensions.ts b/examples/snippets/metrics/setDefaultDimensions.ts similarity index 100% rename from docs/snippets/metrics/setDefaultDimensions.ts rename to examples/snippets/metrics/setDefaultDimensions.ts diff --git a/docs/snippets/metrics/singleMetricDifferentDimsDecorator.ts b/examples/snippets/metrics/singleMetricDifferentDimsDecorator.ts similarity index 100% rename from docs/snippets/metrics/singleMetricDifferentDimsDecorator.ts rename to examples/snippets/metrics/singleMetricDifferentDimsDecorator.ts diff --git a/docs/snippets/metrics/singleMetricDifferentDimsMiddy.ts b/examples/snippets/metrics/singleMetricDifferentDimsMiddy.ts similarity index 100% rename from docs/snippets/metrics/singleMetricDifferentDimsMiddy.ts rename to examples/snippets/metrics/singleMetricDifferentDimsMiddy.ts diff --git a/docs/snippets/metrics/throwOnEmptyMetrics.ts b/examples/snippets/metrics/throwOnEmptyMetrics.ts similarity index 100% rename from docs/snippets/metrics/throwOnEmptyMetrics.ts rename to examples/snippets/metrics/throwOnEmptyMetrics.ts diff --git a/docs/snippets/package.json b/examples/snippets/package.json similarity index 68% rename from docs/snippets/package.json rename to examples/snippets/package.json index 4283f4db6a..05522b499a 100644 --- a/docs/snippets/package.json +++ b/examples/snippets/package.json @@ -1,5 +1,5 @@ { - "name": "docs", + "name": "code-snippets", "version": "2.1.0", "description": "A collection code snippets for the Powertools for AWS Lambda (TypeScript) docs", "author": { @@ -16,8 +16,8 @@ }, "lint-staged": { "*.{js,ts}": "npm run lint-fix", - "*.json": "prettier --write \"**/samples/*.json\" --single-quote false", - "*.yaml": "prettier --write \"**/templates/sam/*.yaml\"" + "*.json": "prettier --write --single-quote false", + "*.yaml": "prettier --write" }, "license": "MIT-0", "repository": { @@ -29,17 +29,24 @@ }, "homepage": "https://github.com/aws-powertools/powertools-lambda-typescript#readme", "devDependencies": { + "@aws-lambda-powertools/batch": "^2.1.0", + "@aws-lambda-powertools/idempotency": "^2.1.0", + "@aws-lambda-powertools/jmespath": "^2.1.0", + "@aws-lambda-powertools/logger": "^2.1.0", + "@aws-lambda-powertools/metrics": "^2.1.0", + "@aws-lambda-powertools/parameters": "^2.1.0", + "@aws-lambda-powertools/parser": "^2.1.0", + "@aws-lambda-powertools/tracer": "^2.1.0", "@aws-sdk/client-appconfigdata": "^3.556.0", "@aws-sdk/client-dynamodb": "^3.556.0", "@aws-sdk/client-secrets-manager": "^3.556.0", - "@aws-sdk/client-ssm": "^3.556.0", + "@aws-sdk/client-ssm": "^3.562.0", "@aws-sdk/util-dynamodb": "^3.556.0", "@middy/core": "^4.7.0", - "aws-sdk": "^2.1605.0", + "aws-sdk": "^2.1606.0", "aws-sdk-client-mock": "^4.0.0", "aws-sdk-client-mock-jest": "^4.0.0", - "axios": "^1.6.8", "hashi-vault-js": "^0.4.14", - "zod": "^3.22.5" + "zod": "^3.23.4" } } diff --git a/docs/snippets/parameters/adjustingCacheTTL.ts b/examples/snippets/parameters/adjustingCacheTTL.ts similarity index 100% rename from docs/snippets/parameters/adjustingCacheTTL.ts rename to examples/snippets/parameters/adjustingCacheTTL.ts diff --git a/docs/snippets/parameters/appConfigProvider.ts b/examples/snippets/parameters/appConfigProvider.ts similarity index 100% rename from docs/snippets/parameters/appConfigProvider.ts rename to examples/snippets/parameters/appConfigProvider.ts diff --git a/docs/snippets/parameters/appConfigProviderCustomClient.ts b/examples/snippets/parameters/appConfigProviderCustomClient.ts similarity index 100% rename from docs/snippets/parameters/appConfigProviderCustomClient.ts rename to examples/snippets/parameters/appConfigProviderCustomClient.ts diff --git a/docs/snippets/parameters/clientConfig.ts b/examples/snippets/parameters/clientConfig.ts similarity index 100% rename from docs/snippets/parameters/clientConfig.ts rename to examples/snippets/parameters/clientConfig.ts diff --git a/docs/snippets/parameters/customProviderVault.ts b/examples/snippets/parameters/customProviderVault.ts similarity index 98% rename from docs/snippets/parameters/customProviderVault.ts rename to examples/snippets/parameters/customProviderVault.ts index 91490f45a7..8e86c933dc 100644 --- a/docs/snippets/parameters/customProviderVault.ts +++ b/examples/snippets/parameters/customProviderVault.ts @@ -4,7 +4,7 @@ import Vault from 'hashi-vault-js'; import type { HashiCorpVaultProviderOptions, HashiCorpVaultGetOptions, -} from './customProviderVaultTypes'; +} from './customProviderVaultTypes.js'; class HashiCorpVaultProvider extends BaseProvider { public client: Vault; diff --git a/docs/snippets/parameters/customProviderVaultTypes.ts b/examples/snippets/parameters/customProviderVaultTypes.ts similarity index 100% rename from docs/snippets/parameters/customProviderVaultTypes.ts rename to examples/snippets/parameters/customProviderVaultTypes.ts diff --git a/docs/snippets/parameters/customProviderVaultUsage.ts b/examples/snippets/parameters/customProviderVaultUsage.ts similarity index 81% rename from docs/snippets/parameters/customProviderVaultUsage.ts rename to examples/snippets/parameters/customProviderVaultUsage.ts index 203724b69e..b86b51e2d8 100644 --- a/docs/snippets/parameters/customProviderVaultUsage.ts +++ b/examples/snippets/parameters/customProviderVaultUsage.ts @@ -1,4 +1,4 @@ -import { HashiCorpVaultProvider } from './customProviderVault'; +import { HashiCorpVaultProvider } from './customProviderVault.js'; const secretsProvider = new HashiCorpVaultProvider({ url: 'https://vault.example.com:8200/v1', diff --git a/docs/snippets/parameters/dynamoDBProvider.ts b/examples/snippets/parameters/dynamoDBProvider.ts similarity index 100% rename from docs/snippets/parameters/dynamoDBProvider.ts rename to examples/snippets/parameters/dynamoDBProvider.ts diff --git a/docs/snippets/parameters/dynamoDBProviderCustomClient.ts b/examples/snippets/parameters/dynamoDBProviderCustomClient.ts similarity index 100% rename from docs/snippets/parameters/dynamoDBProviderCustomClient.ts rename to examples/snippets/parameters/dynamoDBProviderCustomClient.ts diff --git a/docs/snippets/parameters/dynamoDBProviderCustomizeTable.ts b/examples/snippets/parameters/dynamoDBProviderCustomizeTable.ts similarity index 100% rename from docs/snippets/parameters/dynamoDBProviderCustomizeTable.ts rename to examples/snippets/parameters/dynamoDBProviderCustomizeTable.ts diff --git a/docs/snippets/parameters/dynamoDBProviderLocal.ts b/examples/snippets/parameters/dynamoDBProviderLocal.ts similarity index 100% rename from docs/snippets/parameters/dynamoDBProviderLocal.ts rename to examples/snippets/parameters/dynamoDBProviderLocal.ts diff --git a/docs/snippets/parameters/dynamoDBProviderMultiple.ts b/examples/snippets/parameters/dynamoDBProviderMultiple.ts similarity index 100% rename from docs/snippets/parameters/dynamoDBProviderMultiple.ts rename to examples/snippets/parameters/dynamoDBProviderMultiple.ts diff --git a/docs/snippets/parameters/forceFetch.ts b/examples/snippets/parameters/forceFetch.ts similarity index 100% rename from docs/snippets/parameters/forceFetch.ts rename to examples/snippets/parameters/forceFetch.ts diff --git a/docs/snippets/parameters/getAppConfig.ts b/examples/snippets/parameters/getAppConfig.ts similarity index 100% rename from docs/snippets/parameters/getAppConfig.ts rename to examples/snippets/parameters/getAppConfig.ts diff --git a/docs/snippets/parameters/getParameter.ts b/examples/snippets/parameters/getParameter.ts similarity index 100% rename from docs/snippets/parameters/getParameter.ts rename to examples/snippets/parameters/getParameter.ts diff --git a/docs/snippets/parameters/getParameters.ts b/examples/snippets/parameters/getParameters.ts similarity index 100% rename from docs/snippets/parameters/getParameters.ts rename to examples/snippets/parameters/getParameters.ts diff --git a/docs/snippets/parameters/getParametersByName.ts b/examples/snippets/parameters/getParametersByName.ts similarity index 100% rename from docs/snippets/parameters/getParametersByName.ts rename to examples/snippets/parameters/getParametersByName.ts diff --git a/docs/snippets/parameters/getParametersByNameGracefulErrorHandling.ts b/examples/snippets/parameters/getParametersByNameGracefulErrorHandling.ts similarity index 100% rename from docs/snippets/parameters/getParametersByNameGracefulErrorHandling.ts rename to examples/snippets/parameters/getParametersByNameGracefulErrorHandling.ts diff --git a/docs/snippets/parameters/getSecret.ts b/examples/snippets/parameters/getSecret.ts similarity index 100% rename from docs/snippets/parameters/getSecret.ts rename to examples/snippets/parameters/getSecret.ts diff --git a/docs/snippets/parameters/sdkOptions.ts b/examples/snippets/parameters/sdkOptions.ts similarity index 100% rename from docs/snippets/parameters/sdkOptions.ts rename to examples/snippets/parameters/sdkOptions.ts diff --git a/docs/snippets/parameters/secretsProvider.ts b/examples/snippets/parameters/secretsProvider.ts similarity index 100% rename from docs/snippets/parameters/secretsProvider.ts rename to examples/snippets/parameters/secretsProvider.ts diff --git a/docs/snippets/parameters/secretsProviderCustomClient.ts b/examples/snippets/parameters/secretsProviderCustomClient.ts similarity index 100% rename from docs/snippets/parameters/secretsProviderCustomClient.ts rename to examples/snippets/parameters/secretsProviderCustomClient.ts diff --git a/docs/snippets/parameters/ssmProvider.ts b/examples/snippets/parameters/ssmProvider.ts similarity index 100% rename from docs/snippets/parameters/ssmProvider.ts rename to examples/snippets/parameters/ssmProvider.ts diff --git a/docs/snippets/parameters/ssmProviderCustomClient.ts b/examples/snippets/parameters/ssmProviderCustomClient.ts similarity index 100% rename from docs/snippets/parameters/ssmProviderCustomClient.ts rename to examples/snippets/parameters/ssmProviderCustomClient.ts diff --git a/docs/snippets/parameters/ssmProviderDecryptAndRecursive.ts b/examples/snippets/parameters/ssmProviderDecryptAndRecursive.ts similarity index 100% rename from docs/snippets/parameters/ssmProviderDecryptAndRecursive.ts rename to examples/snippets/parameters/ssmProviderDecryptAndRecursive.ts diff --git a/docs/snippets/parameters/testingYourCodeClearCache.ts b/examples/snippets/parameters/testingYourCodeClearCache.ts similarity index 100% rename from docs/snippets/parameters/testingYourCodeClearCache.ts rename to examples/snippets/parameters/testingYourCodeClearCache.ts diff --git a/docs/snippets/parameters/testingYourCodeClientHandler.ts b/examples/snippets/parameters/testingYourCodeClientHandler.ts similarity index 100% rename from docs/snippets/parameters/testingYourCodeClientHandler.ts rename to examples/snippets/parameters/testingYourCodeClientHandler.ts diff --git a/docs/snippets/parameters/testingYourCodeClientJestMock.ts b/examples/snippets/parameters/testingYourCodeClientJestMock.ts similarity index 100% rename from docs/snippets/parameters/testingYourCodeClientJestMock.ts rename to examples/snippets/parameters/testingYourCodeClientJestMock.ts diff --git a/docs/snippets/parameters/testingYourCodeFunctionsHandler.ts b/examples/snippets/parameters/testingYourCodeFunctionsHandler.ts similarity index 100% rename from docs/snippets/parameters/testingYourCodeFunctionsHandler.ts rename to examples/snippets/parameters/testingYourCodeFunctionsHandler.ts diff --git a/docs/snippets/parameters/testingYourCodeFunctionsJestMock.ts b/examples/snippets/parameters/testingYourCodeFunctionsJestMock.ts similarity index 100% rename from docs/snippets/parameters/testingYourCodeFunctionsJestMock.ts rename to examples/snippets/parameters/testingYourCodeFunctionsJestMock.ts diff --git a/docs/snippets/parameters/testingYourCodeProvidersHandler.ts b/examples/snippets/parameters/testingYourCodeProvidersHandler.ts similarity index 100% rename from docs/snippets/parameters/testingYourCodeProvidersHandler.ts rename to examples/snippets/parameters/testingYourCodeProvidersHandler.ts diff --git a/docs/snippets/parameters/testingYourCodeProvidersJestMock.ts b/examples/snippets/parameters/testingYourCodeProvidersJestMock.ts similarity index 100% rename from docs/snippets/parameters/testingYourCodeProvidersJestMock.ts rename to examples/snippets/parameters/testingYourCodeProvidersJestMock.ts diff --git a/docs/snippets/parameters/transform.ts b/examples/snippets/parameters/transform.ts similarity index 100% rename from docs/snippets/parameters/transform.ts rename to examples/snippets/parameters/transform.ts diff --git a/docs/snippets/parameters/transformAuto.ts b/examples/snippets/parameters/transformAuto.ts similarity index 100% rename from docs/snippets/parameters/transformAuto.ts rename to examples/snippets/parameters/transformAuto.ts diff --git a/docs/snippets/parameters/transformPartialFailures.ts b/examples/snippets/parameters/transformPartialFailures.ts similarity index 100% rename from docs/snippets/parameters/transformPartialFailures.ts rename to examples/snippets/parameters/transformPartialFailures.ts diff --git a/docs/snippets/parameters/transformProvider.ts b/examples/snippets/parameters/transformProvider.ts similarity index 100% rename from docs/snippets/parameters/transformProvider.ts rename to examples/snippets/parameters/transformProvider.ts diff --git a/docs/snippets/parser/decorator.ts b/examples/snippets/parser/decorator.ts similarity index 100% rename from docs/snippets/parser/decorator.ts rename to examples/snippets/parser/decorator.ts diff --git a/docs/snippets/parser/envelopeDecorator.ts b/examples/snippets/parser/envelopeDecorator.ts similarity index 100% rename from docs/snippets/parser/envelopeDecorator.ts rename to examples/snippets/parser/envelopeDecorator.ts diff --git a/docs/snippets/parser/envelopeMiddy.ts b/examples/snippets/parser/envelopeMiddy.ts similarity index 100% rename from docs/snippets/parser/envelopeMiddy.ts rename to examples/snippets/parser/envelopeMiddy.ts diff --git a/docs/snippets/parser/examplePayload.json b/examples/snippets/parser/examplePayload.json similarity index 100% rename from docs/snippets/parser/examplePayload.json rename to examples/snippets/parser/examplePayload.json diff --git a/docs/snippets/parser/extend.ts b/examples/snippets/parser/extend.ts similarity index 100% rename from docs/snippets/parser/extend.ts rename to examples/snippets/parser/extend.ts diff --git a/docs/snippets/parser/manual.ts b/examples/snippets/parser/manual.ts similarity index 100% rename from docs/snippets/parser/manual.ts rename to examples/snippets/parser/manual.ts diff --git a/docs/snippets/parser/manualSafeParse.ts b/examples/snippets/parser/manualSafeParse.ts similarity index 93% rename from docs/snippets/parser/manualSafeParse.ts rename to examples/snippets/parser/manualSafeParse.ts index 17106c1bda..ad371d3a4c 100644 --- a/docs/snippets/parser/manualSafeParse.ts +++ b/examples/snippets/parser/manualSafeParse.ts @@ -30,6 +30,6 @@ export const handler = async ( : logger.error('Event parsing failed', parsedEvent.error); const parsedEvenlope = EventBridgeEnvelope.safeParse(event, orderSchema); // (2)! parsedEvenlope.success - ? logger.info('Event envelope parsed successfully', parsedEvenlope.data) + ? logger.info('Event envelope parsed successfully') : logger.error('Event envelope parsing failed', parsedEvenlope.error); }; diff --git a/docs/snippets/parser/middy.ts b/examples/snippets/parser/middy.ts similarity index 100% rename from docs/snippets/parser/middy.ts rename to examples/snippets/parser/middy.ts diff --git a/docs/snippets/parser/refine.ts b/examples/snippets/parser/refine.ts similarity index 100% rename from docs/snippets/parser/refine.ts rename to examples/snippets/parser/refine.ts diff --git a/docs/snippets/parser/safeParseDecorator.ts b/examples/snippets/parser/safeParseDecorator.ts similarity index 100% rename from docs/snippets/parser/safeParseDecorator.ts rename to examples/snippets/parser/safeParseDecorator.ts diff --git a/docs/snippets/parser/safeParseMiddy.ts b/examples/snippets/parser/safeParseMiddy.ts similarity index 100% rename from docs/snippets/parser/safeParseMiddy.ts rename to examples/snippets/parser/safeParseMiddy.ts diff --git a/docs/snippets/parser/schema.ts b/examples/snippets/parser/schema.ts similarity index 100% rename from docs/snippets/parser/schema.ts rename to examples/snippets/parser/schema.ts diff --git a/docs/snippets/parser/types.ts b/examples/snippets/parser/types.ts similarity index 100% rename from docs/snippets/parser/types.ts rename to examples/snippets/parser/types.ts diff --git a/docs/snippets/tracer/accessRootTraceId.ts b/examples/snippets/tracer/accessRootTraceId.ts similarity index 81% rename from docs/snippets/tracer/accessRootTraceId.ts rename to examples/snippets/tracer/accessRootTraceId.ts index 2491f7530f..54139f8f1c 100644 --- a/docs/snippets/tracer/accessRootTraceId.ts +++ b/examples/snippets/tracer/accessRootTraceId.ts @@ -2,11 +2,9 @@ import { Tracer } from '@aws-lambda-powertools/tracer'; const tracer = new Tracer({ serviceName: 'serverlessAirline' }); -export const handler = async ( - _event: unknown, - _context: unknown -): Promise => { +export const handler = async (): Promise => { try { + throw new Error('Something went wrong'); } catch (err) { const rootTraceId = tracer.getRootXrayTraceId(); diff --git a/docs/snippets/tracer/basicUsage.ts b/examples/snippets/tracer/basicUsage.ts similarity index 100% rename from docs/snippets/tracer/basicUsage.ts rename to examples/snippets/tracer/basicUsage.ts diff --git a/docs/snippets/tracer/captureAWS.ts b/examples/snippets/tracer/captureAWS.ts similarity index 100% rename from docs/snippets/tracer/captureAWS.ts rename to examples/snippets/tracer/captureAWS.ts diff --git a/docs/snippets/tracer/captureAWSAll.ts b/examples/snippets/tracer/captureAWSAll.ts similarity index 100% rename from docs/snippets/tracer/captureAWSAll.ts rename to examples/snippets/tracer/captureAWSAll.ts diff --git a/docs/snippets/tracer/captureAWSv3.ts b/examples/snippets/tracer/captureAWSv3.ts similarity index 100% rename from docs/snippets/tracer/captureAWSv3.ts rename to examples/snippets/tracer/captureAWSv3.ts diff --git a/examples/snippets/tracer/captureHTTP.ts b/examples/snippets/tracer/captureHTTP.ts new file mode 100644 index 0000000000..f0d3c93321 --- /dev/null +++ b/examples/snippets/tracer/captureHTTP.ts @@ -0,0 +1,11 @@ +import { Tracer } from '@aws-lambda-powertools/tracer'; +import { captureLambdaHandler } from '@aws-lambda-powertools/tracer/middleware'; +import middy from '@middy/core'; + +const tracer = new Tracer({ serviceName: 'serverlessAirline' }); + +export const handler = middy( + async (_event: unknown, _context: unknown): Promise => { + await fetch('https://httpbin.org/status/200'); + } +).use(captureLambdaHandler(tracer)); diff --git a/docs/snippets/tracer/captureMethodDecorator.ts b/examples/snippets/tracer/captureMethodDecorator.ts similarity index 100% rename from docs/snippets/tracer/captureMethodDecorator.ts rename to examples/snippets/tracer/captureMethodDecorator.ts diff --git a/docs/snippets/tracer/captureMethodManual.ts b/examples/snippets/tracer/captureMethodManual.ts similarity index 100% rename from docs/snippets/tracer/captureMethodManual.ts rename to examples/snippets/tracer/captureMethodManual.ts diff --git a/docs/snippets/tracer/decorator.ts b/examples/snippets/tracer/decorator.ts similarity index 100% rename from docs/snippets/tracer/decorator.ts rename to examples/snippets/tracer/decorator.ts diff --git a/docs/snippets/tracer/disableCaptureResponseHandler.ts b/examples/snippets/tracer/disableCaptureResponseHandler.ts similarity index 100% rename from docs/snippets/tracer/disableCaptureResponseHandler.ts rename to examples/snippets/tracer/disableCaptureResponseHandler.ts diff --git a/docs/snippets/tracer/disableCaptureResponseMethod.ts b/examples/snippets/tracer/disableCaptureResponseMethod.ts similarity index 100% rename from docs/snippets/tracer/disableCaptureResponseMethod.ts rename to examples/snippets/tracer/disableCaptureResponseMethod.ts diff --git a/docs/snippets/tracer/disableCaptureResponseMiddy.ts b/examples/snippets/tracer/disableCaptureResponseMiddy.ts similarity index 100% rename from docs/snippets/tracer/disableCaptureResponseMiddy.ts rename to examples/snippets/tracer/disableCaptureResponseMiddy.ts diff --git a/docs/snippets/tracer/escapeHatch.ts b/examples/snippets/tracer/escapeHatch.ts similarity index 100% rename from docs/snippets/tracer/escapeHatch.ts rename to examples/snippets/tracer/escapeHatch.ts diff --git a/docs/snippets/tracer/manual.ts b/examples/snippets/tracer/manual.ts similarity index 100% rename from docs/snippets/tracer/manual.ts rename to examples/snippets/tracer/manual.ts diff --git a/docs/snippets/tracer/middy.ts b/examples/snippets/tracer/middy.ts similarity index 100% rename from docs/snippets/tracer/middy.ts rename to examples/snippets/tracer/middy.ts diff --git a/docs/snippets/tracer/putAnnotation.ts b/examples/snippets/tracer/putAnnotation.ts similarity index 100% rename from docs/snippets/tracer/putAnnotation.ts rename to examples/snippets/tracer/putAnnotation.ts diff --git a/docs/snippets/tracer/putMetadata.ts b/examples/snippets/tracer/putMetadata.ts similarity index 100% rename from docs/snippets/tracer/putMetadata.ts rename to examples/snippets/tracer/putMetadata.ts diff --git a/docs/snippets/tracer/sam.ts b/examples/snippets/tracer/sam.ts similarity index 100% rename from docs/snippets/tracer/sam.ts rename to examples/snippets/tracer/sam.ts diff --git a/examples/snippets/tsconfig.json b/examples/snippets/tsconfig.json new file mode 100644 index 0000000000..f75f690f30 --- /dev/null +++ b/examples/snippets/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "baseUrl": ".", + "noEmit": true + } +} diff --git a/lerna.json b/lerna.json index 84424e6cab..65afadf4f6 100644 --- a/lerna.json +++ b/lerna.json @@ -12,7 +12,7 @@ "packages/parser", "examples/app", "layers", - "docs/snippets" + "examples/snippets" ], "version": "2.1.0", "npmClient": "npm", diff --git a/package-lock.json b/package-lock.json index dd0d8a6fdc..07e9fcb37d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "packages/batch", "packages/testing", "packages/parser", - "docs/snippets", + "examples/snippets", "layers", "examples/app" ], @@ -53,24 +53,11 @@ "node": ">=16" } }, - "docs/snippets": { - "name": "docs", + "app/snippets": { + "name": "code-snippets", "version": "2.1.0", - "license": "MIT-0", - "devDependencies": { - "@aws-sdk/client-appconfigdata": "^3.556.0", - "@aws-sdk/client-dynamodb": "^3.556.0", - "@aws-sdk/client-secrets-manager": "^3.556.0", - "@aws-sdk/client-ssm": "^3.556.0", - "@aws-sdk/util-dynamodb": "^3.556.0", - "@middy/core": "^4.7.0", - "aws-sdk": "^2.1605.0", - "aws-sdk-client-mock": "^4.0.0", - "aws-sdk-client-mock-jest": "^4.0.0", - "axios": "^1.6.8", - "hashi-vault-js": "^0.4.14", - "zod": "^3.22.5" - } + "extraneous": true, + "license": "MIT-0" }, "examples/app": { "name": "powertools-sample-app", @@ -111,6 +98,32 @@ "typescript": "^5.4.5" } }, + "examples/snippets": { + "name": "code-snippets", + "version": "2.1.0", + "license": "MIT-0", + "devDependencies": { + "@aws-lambda-powertools/batch": "^2.1.0", + "@aws-lambda-powertools/idempotency": "^2.1.0", + "@aws-lambda-powertools/jmespath": "^2.1.0", + "@aws-lambda-powertools/logger": "^2.1.0", + "@aws-lambda-powertools/metrics": "^2.1.0", + "@aws-lambda-powertools/parameters": "^2.1.0", + "@aws-lambda-powertools/parser": "^2.1.0", + "@aws-lambda-powertools/tracer": "^2.1.0", + "@aws-sdk/client-appconfigdata": "^3.556.0", + "@aws-sdk/client-dynamodb": "^3.556.0", + "@aws-sdk/client-secrets-manager": "^3.556.0", + "@aws-sdk/client-ssm": "^3.562.0", + "@aws-sdk/util-dynamodb": "^3.556.0", + "@middy/core": "^4.7.0", + "aws-sdk": "^2.1606.0", + "aws-sdk-client-mock": "^4.0.0", + "aws-sdk-client-mock-jest": "^4.0.0", + "hashi-vault-js": "^0.4.14", + "zod": "^3.23.4" + } + }, "layers": { "version": "2.1.0", "license": "MIT-0", @@ -582,9 +595,9 @@ } }, "node_modules/@aws-sdk/client-ssm": { - "version": "3.556.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/client-ssm/-/client-ssm-3.556.0.tgz", - "integrity": "sha512-uGrzSEcxcldW2vOirEYyr/lbO5n4FV5O36Sm4Q/eXtBO8FOUM5Fydi8mg+3xAIW7I3wEU79ygp7+FpM6u9W+9g==", + "version": "3.562.0", + "resolved": "https://registry.npmjs.org/@aws-sdk/client-ssm/-/client-ssm-3.562.0.tgz", + "integrity": "sha512-THgtV7yKI06YN9us5u0appRXPAWHoWo7JKh4sUZDFGmxMX87WqTKRL/Z4tLL+fgBN0BtNorjRdWgc63fsKUTLA==", "dependencies": { "@aws-crypto/sha256-browser": "3.0.0", "@aws-crypto/sha256-js": "3.0.0", @@ -6049,9 +6062,9 @@ } }, "node_modules/aws-sdk": { - "version": "2.1605.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1605.0.tgz", - "integrity": "sha512-/wtOuF7WgkbN6YL3xJ+FB54kvIAfnP/DQVDaE6rSYv6ft0xr01Si94NgQWhb5OcFkFfRAC4auZX8PiFNtOi9xQ==", + "version": "2.1606.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1606.0.tgz", + "integrity": "sha512-Sg1y0p93XI0ce86D9mi402sKMiH7LDoq6k3YzMja9yA0i3i0Pg3py4jjZ7p3HlKNOsDUF0t+9DLdCjtbTbuM6w==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -6882,6 +6895,10 @@ "node": ">= 0.12.0" } }, + "node_modules/code-snippets": { + "resolved": "examples/snippets", + "link": true + }, "node_modules/collect-v8-coverage": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/collect-v8-coverage/-/collect-v8-coverage-1.0.2.tgz", @@ -7412,10 +7429,6 @@ "node": ">=8" } }, - "node_modules/docs": { - "resolved": "docs/snippets", - "link": true - }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", @@ -17498,9 +17511,9 @@ } }, "node_modules/zod": { - "version": "3.22.5", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.5.tgz", - "integrity": "sha512-HqnGsCdVZ2xc0qWPLdO25WnseXThh0kEYKIdV5F/hTHO75hNZFp8thxSeHhiPrHZKrFTo1SOgkAj9po5bexZlw==", + "version": "3.23.4", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.4.tgz", + "integrity": "sha512-/AtWOKbBgjzEYYQRNfoGKHObgfAZag6qUJX1VbHo2PRBgS+wfWagEY2mizjfyAPcGesrJOcx/wcl0L9WnVrHFw==", "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/package.json b/package.json index e186c54208..ac45e9bb4e 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "packages/batch", "packages/testing", "packages/parser", - "docs/snippets", + "examples/snippets", "layers", "examples/app" ], diff --git a/typedoc.base.json b/typedoc.base.json index ce978059e9..6ee9d0352c 100644 --- a/typedoc.base.json +++ b/typedoc.base.json @@ -6,6 +6,6 @@ "**/node_modules/**", "**/*.test.ts", "**/*.json", - "docs/snippets" + "examples/snippets" ] } \ No newline at end of file diff --git a/typedoc.json b/typedoc.json index c277d0cc80..daadd7bc2e 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,5 +1,7 @@ { - "entryPoints": ["packages/*"], + "entryPoints": [ + "packages/*" + ], "entryPointStrategy": "packages", "name": "Powertools for AWS Lambda (Typescript) API Reference", "readme": "README.md", @@ -8,7 +10,6 @@ "**/node_modules/**", "**/*.test.ts", "**/*.json", - "docs/snippets", "layers", "examples/**" ],