Skip to content

Commit

Permalink
fix(docs): remove overrides, introduce changes to code-snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
niko-achilles committed Jan 25, 2023
1 parent 07c548d commit cc8d108
Show file tree
Hide file tree
Showing 53 changed files with 11,510 additions and 14,781 deletions.
13 changes: 1 addition & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,5 @@ module.exports = {
'prefer-arrow-callback': 'error',
quotes: [ 'error', 'single', { allowTemplateLiterals: true } ],
semi: [ 'error', 'always' ]
},
overrides:[
{
files:['docs/snippets/**/*.ts'],
rules:{
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/explicit-member-accessibility': 'warn',
'@typescript-eslint/no-var-requires': 'warn'
}
}
]
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ jobs:
if: steps.cache-node-modules.outputs.cache-hit == 'true'
run: |
npm run build -w packages/commons
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics & npm run build -w packages/parameters & npm run build -w packages/idempotency
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics & npm run build -w packages/parameters & npm run build -w packages/idempotency & npm run build -w docs/snippets
- name: Run linting
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics -w packages/parameters -w packages/idempotency
run: npm run lint -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics -w packages/parameters -w packages/idempotency -w docs/snippets
- name: Run unit tests
run: npm t -w packages/commons -w packages/logger -w packages/tracer -w packages/metrics -w packages/parameters -w packages/idempotency
check-examples:
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/appendKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const logger = new Logger({
// extra_key: "some-value"
// });

export const handler = async (_event: any, _context: any): Promise<unknown> => {
export const handler = async (_event: unknown, _context: unknown): Promise<unknown> => {

// If you don't want to log the "extra_key" attribute in your logs, you can remove it
logger.removeKeys(['extra_key']);
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/basicUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { Logger } from '@aws-lambda-powertools/logger';
const logger = new Logger({ serviceName: 'serverlessAirline' });

export const handler = async (_event, _context): Promise<void> => {
// ...
logger.info('Hello World');
};
2 changes: 1 addition & 1 deletion docs/snippets/logger/clearStateDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const logger = new Logger({
class Lambda implements LambdaInterface {
// Enable the clear state flag
@logger.injectLambdaContext({ clearState: true })
public async handler(_event: any, _context: any): Promise<void> {
public async handler(event: unknown, _context: unknown): Promise<void> {
// Persistent attributes added inside the handler will NOT be cached
// across invocations
if (event['special_key'] === '123456'){
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/clearStateMiddy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const logger = new Logger({
}
});

const lambdaHandler = async (event: { special_key: string }, _context: any): Promise<void> => {
const lambdaHandler = async (event: { special_key: string }, _context: unknown): Promise<void> => {
// Persistent attributes added inside the handler will NOT be cached
// across invocations
if (event['special_key'] === '123456') {
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/createChild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const childLogger = logger.createChild({
logLevel: 'ERROR'
});

export const handler = async (_event: any, _context: any): Promise<void> => {
export const handler = async (_event: unknown, _context: unknown): Promise<void> => {

logger.info('This is an INFO log, from the parent logger');
logger.error('This is an ERROR log, from the parent logger');
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const logger = new Logger();
class Lambda implements LambdaInterface {
// Decorate your handler class method
@logger.injectLambdaContext()
public async handler(_event: any, _context: any): Promise<void> {
public async handler(_event: unknown, _context: unknown): Promise<void> {
logger.info('This is an INFO log with some context');
}

Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/eventDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const logger = new Logger();
class Lambda implements LambdaInterface {
// Set the log event flag to true
@logger.injectLambdaContext({ logEvent: true })
public async handler(_event: any, _context: any): Promise<void> {
public async handler(_event: unknown, _context: unknown): Promise<void> {
logger.info('This is an INFO log with some context');
}

Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/eventMiddy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import middy from '@middy/core';

const logger = new Logger();

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
const lambdaHandler = async (_event: unknown, _context: unknown): Promise<void> => {
logger.info('This is an INFO log with some context');
};

Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/extraData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger();

export const handler = async (event: any, _context: any): Promise<unknown> => {
export const handler = async (event: unknown, _context: unknown): Promise<unknown> => {

const myImportantVariable = {
foo: 'bar'
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/logError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger();

export const handler = async (_event: any, _context: any): Promise<void> => {
export const handler = async (_event: unknown, _context: unknown): Promise<void> => {

try {
throw new Error('Unexpected error #1');
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/logSampling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const logger = new Logger({
sampleRateValue: 0.5
});

export const handler = async (_event: any, _context: any): Promise<void> => {
export const handler = async (_event: unknown, _context: unknown): Promise<void> => {

// This log item (equal to log level 'ERROR') will be printed to standard output
// in all Lambda invocations
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/logger/middy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import middy from '@middy/core';

const logger = new Logger();

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
const lambdaHandler = async (_event: unknown, _context: unknown): Promise<void> => {
logger.info('This is an INFO log with some context');
};

Expand Down
1 change: 1 addition & 0 deletions docs/snippets/logger/sam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Logger } from '@aws-lambda-powertools/logger';

// Logger parameters fetched from the environment variables (see template.yaml tab)
const logger = new Logger();
logger.info('Hello World');

// You can also pass the parameters in the constructor
// const logger = new Logger({
Expand Down
15 changes: 1 addition & 14 deletions docs/snippets/logger/unitTesting.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
const dummyContext = {
callbackWaitsForEmptyEventLoop: true,
functionVersion: '$LATEST',
functionName: 'foo-bar-function',
memoryLimitInMB: '128',
logGroupName: '/aws/lambda/foo-bar-function',
logStreamName: '2021/03/09/[$LATEST]abcdef123456abcdef123456abcdef123456',
invokedFunctionArn: 'arn:aws:lambda:eu-west-1:123456789012:function:foo-bar-function',
awsRequestId: 'c6af9ac6-7b61-11e6-9a41-93e812345678',
getRemainingTimeInMillis: () => 1234,
done: () => console.log('Done!'),
fail: () => console.log('Failed!'),
succeed: () => console.log('Succeeded!'),
};
import { ContextExamples as dummyContext } from '@aws-lambda-powertools/commons';

describe('MyUnitTest', () => {

Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/metrics/addMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import middy from '@middy/core';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
const lambdaHandler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
metrics.addMetadata('bookingId', '7051cd10-6283-11ec-90d6-0242ac120003');
};
Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/metrics/basicUsage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Metrics } from '@aws-lambda-powertools/metrics';
import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

export const handler = async (_event, _context): Promise<void> => {
// ...
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
};
2 changes: 1 addition & 1 deletion docs/snippets/metrics/captureColdStartMetricDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orde
export class MyFunction implements LambdaInterface {

@metrics.logMetrics({ captureColdStartMetric: true })
public async handler(_event: any, _context: any): Promise<void> {
public async handler(_event: unknown, _context: unknown): Promise<void> {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
}
}
2 changes: 1 addition & 1 deletion docs/snippets/metrics/captureColdStartMetricMiddy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import middy from '@middy/core';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
const lambdaHandler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
};

Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/metrics/createMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

export const handler = async (_event: any, _context: any): Promise<void> => {
export const handler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
metrics.publishStoredMetrics();
};
2 changes: 1 addition & 1 deletion docs/snippets/metrics/customDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

export const handler = async (_event: any, _context: any): Promise<void> => {
export const handler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addDimension('environment', 'prod');
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
metrics.publishStoredMetrics();
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/metrics/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orde
class Lambda implements LambdaInterface {

@metrics.logMetrics()
public async handler(_event: any, _context: any): Promise<void> {
public async handler(_event: unknown, _context: unknown): Promise<void> {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/metrics/defaultDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ const metrics = new Metrics({
defaultDimensions: { 'environment': 'prod', 'foo': 'bar' }
});

export const handler = async (_event: any, _context: any): Promise<void> => {
export const handler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
};
2 changes: 1 addition & 1 deletion docs/snippets/metrics/defaultDimensionsDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const DEFAULT_DIMENSIONS = { 'environment': 'prod', 'foo': 'bar' };
export class Lambda implements LambdaInterface {
// Decorate your handler class method
@metrics.logMetrics({ defaultDimensions: DEFAULT_DIMENSIONS })
public async handler(_event: any, _context: any): Promise<void> {
public async handler(_event: unknown, _context: unknown): Promise<void> {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/metrics/defaultDimensionsMiddy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import middy from '@middy/core';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
const lambdaHandler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
};

Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/metrics/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

export const handler = async (_event: any, _context: any): Promise<void> => {
export const handler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addMetric('successfulBooking', MetricUnits.Count, 10);
metrics.publishStoredMetrics();
};
2 changes: 1 addition & 1 deletion docs/snippets/metrics/middy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import middy from '@middy/core';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
const lambdaHandler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
};

Expand Down
3 changes: 1 addition & 2 deletions docs/snippets/metrics/multiValueMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
import { Context } from 'aws-lambda';

const metrics = new Metrics({ namespace:'serverlessAirline', serviceName:'orders' });

export const handler = async (event: any, context: Context): Promise<void> => {
export const handler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addMetric('performedActionA', MetricUnits.Count, 2);
// do something else...
metrics.addMetric('performedActionA', MetricUnits.Count, 1);
Expand Down
3 changes: 2 additions & 1 deletion docs/snippets/metrics/sam.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Metrics } from '@aws-lambda-powertools/metrics';
import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';

// Metrics parameters fetched from the environment variables (see template.yaml tab)
const metrics = new Metrics();
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);

// You can also pass the parameters in the constructor
// const metrics = new Metrics({
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/metrics/setDefaultDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
metrics.setDefaultDimensions({ 'environment': 'prod', 'foo': 'bar' });

export const handler = async (event: any, _context: any): Promise<void> => {
export const handler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orde
class Lambda implements LambdaInterface {

@metrics.logMetrics()
public async handler(_event: any, _context: any): Promise<void> {
public async handler(_event: unknown, _context: unknown): Promise<void> {
metrics.addDimension('metricUnit', 'milliseconds');
// This metric will have the "metricUnit" dimension, and no "metricType" dimension:
metrics.addMetric('latency', MetricUnits.Milliseconds, 56);
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/metrics/singleMetricDifferentDimsMiddy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import middy from '@middy/core';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
const lambdaHandler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addDimension('metricUnit', 'milliseconds');
// This metric will have the "metricUnit" dimension, and no "metricType" dimension:
metrics.addMetric('latency', MetricUnits.Milliseconds, 56);
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/metrics/throwOnEmptyMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import middy from '@middy/core';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

const lambdaHandler = async (_event: any, _context: any): Promise<void> => {
const lambdaHandler = async (_event: unknown, _context: unknown): Promise<void> => {
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
};

Expand Down
4 changes: 2 additions & 2 deletions docs/snippets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"devDependencies": {
"@aws-sdk/client-appconfigdata": "^3.245.0",
"@aws-sdk/client-dynamodb": "^3.245.0",
"@aws-sdk/client-s3": "^3.254.0",
"@aws-sdk/client-secrets-manager": "^3.250.0",
"@aws-sdk/client-ssm": "^3.245.0",
"@aws-sdk/util-dynamodb": "^3.245.0"
"@aws-sdk/util-dynamodb": "^3.245.0",
"axios": "^1.2.4"
}
}
2 changes: 1 addition & 1 deletion docs/snippets/tracer/accessRootTraceId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Tracer } from '@aws-lambda-powertools/tracer';

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

export const handler = async (event: unknown, context: Context): Promise<void> => {
export const handler = async (_event: unknown, _context: unknown): Promise<void> => {
try {

} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/tracer/basicUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { Tracer } from '@aws-lambda-powertools/tracer';
const tracer = new Tracer({ serviceName: 'serverlessAirline' });

export const handler = async (_event, _context): Promise<void> => {
// ...
tracer.getSegment();
};
2 changes: 1 addition & 1 deletion docs/snippets/tracer/captureAWS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import { S3 } from 'aws-sdk';
import { Tracer } from '@aws-lambda-powertools/tracer';

const tracer = new Tracer({ serviceName: 'serverlessAirline' });
const s3 = tracer.captureAWSClient(new S3());
tracer.captureAWSClient(new S3());
6 changes: 3 additions & 3 deletions docs/snippets/tracer/captureAWSAll.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tracer } from '@aws-lambda-powertools/tracer';
// import { Tracer } from '@aws-lambda-powertools/tracer';

const tracer = new Tracer({ serviceName: 'serverlessAirline' });
const AWS = tracer.captureAWS(require('aws-sdk'));
// const tracer = new Tracer({ serviceName: 'serverlessAirline' });
// const AWS = tracer.captureAWS(require('aws-sdk'));
4 changes: 2 additions & 2 deletions docs/snippets/tracer/captureAWSv3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { S3Client } from '@aws-sdk/client-s3';
import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
import { Tracer } from '@aws-lambda-powertools/tracer';

const tracer = new Tracer({ serviceName: 'serverlessAirline' });
const client = tracer.captureAWSv3Client(new S3Client({}));
tracer.captureAWSv3Client(new SecretsManagerClient({}));
Loading

0 comments on commit cc8d108

Please sign in to comment.