Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"root": true,
"assist": {
"actions": {
"source": {
Expand Down
2 changes: 1 addition & 1 deletion docs/features/event-handler/appsync-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ When processing batch of items with `aggregate` enabled, you must format the pay

=== "Error handling with batch of items"

```typescript hl_lines="21-24"
```typescript hl_lines="25-28"
--8<-- "examples/snippets/event-handler/appsync-events/errorHandlingWithBatchOfItems.ts"
```

Expand Down
2 changes: 1 addition & 1 deletion docs/features/event-handler/appsync-graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ You can use an AppSync JavaScript resolver or a VTL response mapping template to

=== "Exception Handling response"

```json hl_lines="11 20"
```json hl_lines="9 18"
--8<-- "examples/snippets/event-handler/appsync-graphql/exceptionHandlingResponse.json"
```

Expand Down
2 changes: 1 addition & 1 deletion docs/features/event-handler/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ You can enable response compression by using the `compress` middleware. This wil

=== "Response"

```json hl_lines="7-9 11 12"
```json hl_lines="4-5 7-8"
--8<-- "examples/snippets/event-handler/rest/samples/advanced_compress_res.json"
```

Expand Down
2 changes: 1 addition & 1 deletion docs/features/tracer.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ You can trace other class methods using the `captureMethod` decorator or any arb

=== "Manual"

```typescript hl_lines="7-13 19 22 26-31"
```typescript hl_lines="7-10 16 21 25 27"
--8<-- "examples/snippets/tracer/captureMethodManual.ts"
```

Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/batch/advancedTracingRecordHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const recordHandler = async (record: SQSRecord): Promise<void> => {
// do something with the item
subsegment?.addMetadata('item', item);
} catch (error) {
subsegment?.addError(error);
subsegment?.addError(error as Error);
throw error;
}
}
Expand Down
12 changes: 12 additions & 0 deletions examples/snippets/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "../../node_modules/@biomejs/biome/configuration_schema.json",
"extends": "//",
"root": false,
"linter": {
"rules": {
"suspicious": {
"useAwait": "off"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ app.onPublish(
payload: { processed: true, original_payload: payload },
});
} catch (error) {
const errorString =
error instanceof Error
? `${error.name} - ${error.message}`
: 'Unknown error';
returnValues.push({
id: payload.id,
error: `${error.name} - ${error.message}`,
error: errorString,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Unit test for AppSync GraphQL Resolver', () => {
const event = onGraphqlEventFactory('listLocations', 'Query');

// Act
const result = (await handler(event, {} as Context)) as Promise<unknown[]>;
const result = (await handler(event, {} as Context)) as unknown[];

// Assess
expect(result).toHaveLength(2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AssertionError } from 'node:assert';
import { AppSyncGraphQLResolver } from '@aws-lambda-powertools/event-handler/appsync-graphql';
import { Logger } from '@aws-lambda-powertools/logger';
import { AssertionError } from 'node:assert';
import type { Context } from 'aws-lambda';

const logger = new Logger({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
},
"errors": [
{
"path": [
"createSomething"
],
"path": ["createSomething"],
"data": null,
"errorType": "AssertionError",
"errorInfo": null,
Expand All @@ -20,4 +18,4 @@
"message": "This is an assertion Error"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"resource": "/logo",
"path": "/logo",
"httpMethod": "GET"
}
}
Original file line number Di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4yNzI1NzYsMzguNCBDNzEuNTA1Mjc1OCwzOC40IDcwLjA2ODM0MjEsMzkuODMwNCA3MC4wNjUxMzQ0LDQxLjU5NjggTDcwLjAyOTg1MjgsNzkuOTk2OCBDNzAuMDI5ODUyOCw4MC44NDggNzAuMzYzNDI2Niw4MS42NjA4IDcwLjk2OTYzMyw4Mi4yNjI0IEM3MS41Njk0MjQ2LDgyLjg2NCA3Mi4zODQxMTQ2LDgzLjIgNzMuMjM3Mjk0MSw4My4yIEwxMDAuMjUzNTczLDgzLjIgTDE2My41OTA5MiwyMTUuNzc2IEMxNjQuMTIzMzU1LDIxNi44ODk2IDE2NS4yNDU5NiwyMTcuNiAxNjYuNDg0MDMyLDIxNy42IEwyMTEuMTkyNTU4LDIxNy42IEMyMTIuOTY2Mjc0LDIxNy42IDIxNC40LDIxNi4xNjY0IDIxNC40LDIxNC40IEwyMTQuNCwxNzYgQzIxNC40LDE3NC4yMzM2IDIxMi45NjYyNzQsMTcyLjggMjExLjE5MjU1OCwxNzIuOCBMMjExLjE5MjU1OCwxNzIuOCBaIiBmaWxsPSIjRkZGRkZGIj48L3BhdGg+CiAgICA8L2c+Cjwvc3ZnPg==",
"multiValueHeaders": {
"Content-Type": [
"image/png"
],
"Content-Encoding": [
"gzip"
]
"Content-Type": ["image/png"],
"Content-Encoding": ["gzip"]
},
"isBase64Encoded": true,
"statusCode": 200
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"resource": "/todos/1",
"path": "/todos/1",
"httpMethod": "GET"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"statusCode": 200,
"multiValueHeaders": {
"Content-Type": [
"application/json"
],
"Content-Encoding": [
"gzip"
]
"Content-Type": ["application/json"],
"Content-Encoding": ["gzip"]
},
"body": "H4sIAAAAAAACE42STU4DMQyFrxJl3QXln96AMyAW7sSDLCVxiJ0Kqerd8TCCUOgii1EmP/783pOPXjmw+N3L0TfB+hz8brvxtC5KGtHvfMCIkzZx0HT5MPmNnziViIr2dIYoeNr8Q1x3xHsjcVadIbkZJoq2RXU8zzQROLseQ9505NzeCNQdMJNBE+UmY4zbzjAJhWtlZ57sB84BWtul+rteH2HPlVgWARwjqXkxpklK5gmEHAQqJBMtFsGVygcKmNVRjG0wxvuzGF2L0dpVUOKMC3bfJNjJgWMrCuZk7cUp02AiD72D6WKHHwUDKbiJs6AZ0VZXKOUx4uNvzdxT+E4mLcMA+6G8nzrLQkaxkNEVrFKW2VGbJCoCY7q2V3+tiv5kGThyxfTecDWbgGz/NfYXhL6ePgF9PnFdPgMAAA==",
"isBase64Encoded": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
},
"body": "{\"status\":\"ok\"}",
"isBase64Encoded": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
},
"body": "{\"todoId\":\"123\",\"task\":\"Example task\",\"completed\":false}",
"isBase64Encoded": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"details": {
"errorName": "Name of the error class"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"statusCode": 500,
"error": "Internal Server Error",
"message": "Internal Server Error"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"Location": "/todos/123"
},
"isBase64Encoded": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"Content-Type": "application/json"
},
"isBase64Encoded": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"x-post-processed-by": "global-middleware"
},
"isBase64Encoded": false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"resource": "/todos/{id}",
"path": "/todos/1",
"httpMethod": "GET"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"path": "/todos",
"httpMethod": "POST",
"body": "{\"title\": \"foo\", \"userId\": 1, \"completed\": false}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
},
"body": "{'message':'pong'}",
"isBase64Encoded": false
}
}
2 changes: 1 addition & 1 deletion examples/snippets/getting-started/patterns-functional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const handler = async (event: unknown, context: Context) => {
throw new Error('An error occurred');
} catch (error) {
logger.error('Error occurred', { error });
tracer.addErrorAsMetadata(error);
tracer.addErrorAsMetadata(error as Error);
throw error;
} finally {
subsegment?.close();
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/logger/basicUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger({ serviceName: 'serverlessAirline' });

export const handler = async (_event, _context): Promise<void> => {
export const handler = async () => {
logger.info('Hello World');
};
6 changes: 3 additions & 3 deletions examples/snippets/logger/unserializableValues.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Logger } from '@aws-lambda-powertools/logger';
import type { CustomReplacerFn } from '@aws-lambda-powertools/logger/types';
import type { CustomJsonReplacerFn } from '@aws-lambda-powertools/logger/types';

const jsonReplacerFn: CustomReplacerFn = (_: string, value: unknown) =>
const jsonReplacerFn: CustomJsonReplacerFn = (_: string, value: unknown) =>
value instanceof Set ? [...value] : value;

const logger = new Logger({ serviceName: 'serverlessAirline', jsonReplacerFn });

export const handler = async (): Promise<void> => {
export const handler = async () => {
logger.info('Serialize with custom serializer', {
serializedValue: new Set([1, 2, 3]),
});
Expand Down
8 changes: 3 additions & 5 deletions examples/snippets/parameters/customProviderVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ class HashiCorpVaultProvider extends BaseProvider {
/**
* Retrieve a secret from HashiCorp Vault.
*
* You can customize the retrieval of the secret by passing options to the function:
* * `maxAge` - The maximum age of the value in cache before fetching a new one (in seconds) (default: 5)
* * `forceFetch` - Whether to always fetch a new value from the store regardless if already available in cache
* * `sdkOptions` - Extra options to pass to the HashiCorp Vault SDK, e.g. `mount` or `version`
*
* @param name - The name of the secret
* @param options - Options to customize the retrieval of the secret
* @param options.maxAge - The maximum age of the value in cache before fetching a new one (in seconds) (default: 5)
* @param options.forceFetch - Whether to always fetch a new value from the store regardless if already available in cache
* @param options.sdkOptions - Extra options to pass to the HashiCorp Vault SDK, e.g. `mount` or `version`
*/
public async get<T extends Record<string, unknown>>(
name: string,
Expand Down
8 changes: 6 additions & 2 deletions examples/snippets/tracer/basicUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { Tracer } from '@aws-lambda-powertools/tracer';

const tracer = new Tracer({ serviceName: 'serverlessAirline' });

export const handler = async (_event, _context): Promise<void> => {
tracer.getSegment();
export const handler = async () => {
const segment = tracer.getSegment();
const subsegment = segment?.addNewSubsegment('subsegment');
subsegment?.addAnnotation('annotationKey', 'annotationValue');
subsegment?.addMetadata('metadataKey', { foo: 'bar' });
subsegment?.close();
};
27 changes: 11 additions & 16 deletions examples/snippets/tracer/captureMethodManual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,26 @@ const tracer = new Tracer({ serviceName: 'serverlessAirline' });
const getChargeId = async (): Promise<unknown> => {
const parentSubsegment = tracer.getSegment(); // This is the subsegment currently active
let subsegment: Subsegment | undefined;
if (parentSubsegment) {
// Create subsegment for the function & set it as active
subsegment = parentSubsegment.addNewSubsegment('### chargeId');
tracer.setSegment(subsegment);
}
subsegment = parentSubsegment?.addNewSubsegment('### chargeId');
subsegment && tracer.setSegment(subsegment);

let res: unknown;
try {
/* ... */
const res = { chargeId: '1234' };

// Add the response as metadata
tracer.addResponseAsMetadata(res, 'chargeId');

return res;
} catch (err) {
// Add the error as metadata
tracer.addErrorAsMetadata(err as Error);
throw err;
} finally {
// Close subsegment
subsegment?.close();
// Set the facade segment as active again, it'll be closed automatically
parentSubsegment && tracer.setSegment(parentSubsegment);
}

if (parentSubsegment && subsegment) {
// Close subsegment (the AWS Lambda one is closed automatically)
subsegment.close();
// Set the facade segment as active again
tracer.setSegment(parentSubsegment);
}

return res;
};

export const handler = async (
Expand Down
Loading