Skip to content

Commit dafe774

Browse files
committed
chore: apply linting to examples
1 parent 4e15662 commit dafe774

File tree

9 files changed

+105
-137
lines changed

9 files changed

+105
-137
lines changed

examples/cdk/src/example-stack.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { Stack, StackProps, Duration } from 'aws-cdk-lib';
22
import { Construct } from 'constructs';
33
import { Table, BillingMode, AttributeType } from 'aws-cdk-lib/aws-dynamodb';
4-
import { NodejsFunction, NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs';
4+
import {
5+
NodejsFunction,
6+
NodejsFunctionProps,
7+
} from 'aws-cdk-lib/aws-lambda-nodejs';
58
import { Runtime, Tracing, LayerVersion } from 'aws-cdk-lib/aws-lambda';
69
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
710
import { RestApi, LambdaIntegration } from 'aws-cdk-lib/aws-apigateway';
@@ -15,7 +18,7 @@ const commonProps: Partial<NodejsFunctionProps> = {
1518
NODE_OPTIONS: '--enable-source-maps', // see https://docs.aws.amazon.com/lambda/latest/dg/typescript-exceptions.html
1619
POWERTOOLS_SERVICE_NAME: 'items-store',
1720
POWERTOOLS_METRICS_NAMESPACE: 'PowertoolsCDKExample',
18-
LOG_LEVEL: 'DEBUG'
21+
LOG_LEVEL: 'DEBUG',
1922
},
2023
bundling: {
2124
externalModules: [
@@ -39,14 +42,17 @@ export class CdkAppStack extends Stack {
3942
partitionKey: {
4043
type: AttributeType.STRING,
4144
name: 'id',
42-
}
45+
},
4346
});
4447

4548
commonProps.layers?.push(
4649
LayerVersion.fromLayerVersionArn(
4750
this,
4851
'powertools-layer',
49-
`arn:aws:lambda:${Stack.of(this).region}:094274105915:layer:AWSLambdaPowertoolsTypeScript:6`)
52+
`arn:aws:lambda:${
53+
Stack.of(this).region
54+
}:094274105915:layer:AWSLambdaPowertoolsTypeScript:6`
55+
)
5056
);
5157

5258
const putItemFn = new NodejsFunction(this, 'put-item-fn', {

examples/sam/.eslintrc.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

examples/sam/src/common/constants.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// Get the DynamoDB table name from environment variables
22
const tableName = process.env.SAMPLE_TABLE;
33

4-
export {
5-
tableName
6-
};
4+
export { tableName };

examples/sam/src/common/dynamodb-client.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,4 @@ const translateConfig = { marshallOptions, unmarshallOptions };
2424
// Create the DynamoDB Document client.
2525
const docClient = DynamoDBDocumentClient.from(ddbClient, translateConfig);
2626

27-
export {
28-
docClient
29-
};
27+
export { docClient };

examples/sam/src/common/powertools.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const awsLambdaPowertoolsVersion = '1.5.0';
66

77
const defaultValues = {
88
region: process.env.AWS_REGION || 'N/A',
9-
executionEnv: process.env.AWS_EXECUTION_ENV || 'N/A'
9+
executionEnv: process.env.AWS_EXECUTION_ENV || 'N/A',
1010
};
1111

1212
const logger = new Logger({
@@ -15,18 +15,14 @@ const logger = new Logger({
1515
logger: {
1616
name: '@aws-lambda-powertools/logger',
1717
version: awsLambdaPowertoolsVersion,
18-
}
18+
},
1919
},
2020
});
2121

2222
const metrics = new Metrics({
23-
defaultDimensions: defaultValues
23+
defaultDimensions: defaultValues,
2424
});
2525

2626
const tracer = new Tracer();
2727

28-
export {
29-
logger,
30-
metrics,
31-
tracer
32-
};
28+
export { logger, metrics, tracer };

examples/sam/src/get-all-items.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
1+
import {
2+
APIGatewayProxyEvent,
3+
APIGatewayProxyResult,
4+
Context,
5+
} from 'aws-lambda';
26
import middy from '@middy/core';
37
import { tableName } from './common/constants';
48
import { logger, tracer, metrics } from './common/powertools';
@@ -12,7 +16,7 @@ import { default as request } from 'phin';
1216
/*
1317
*
1418
* This example uses the Middy middleware instrumentation.
15-
* It is the best choice if your existing code base relies on the Middy middleware engine.
19+
* It is the best choice if your existing code base relies on the Middy middleware engine.
1620
* Powertools offers compatible Middy middleware to make this integration seamless.
1721
* Find more Information in the docs: https://awslabs.github.io/aws-lambda-powertools-typescript/
1822
*
@@ -23,9 +27,14 @@ import { default as request } from 'phin';
2327
* @returns {Object} object - API Gateway Lambda Proxy Output Format
2428
*
2529
*/
26-
const getAllItemsHandler = async (event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> => {
30+
const getAllItemsHandler = async (
31+
event: APIGatewayProxyEvent,
32+
context: Context
33+
): Promise<APIGatewayProxyResult> => {
2734
if (event.httpMethod !== 'GET') {
28-
throw new Error(`getAllItems only accepts GET method, you tried: ${event.httpMethod}`);
35+
throw new Error(
36+
`getAllItems only accepts GET method, you tried: ${event.httpMethod}`
37+
);
2938
}
3039

3140
// Tracer: Add awsRequestId as annotation
@@ -60,30 +69,32 @@ const getAllItemsHandler = async (event: APIGatewayProxyEvent, context: Context)
6069
throw new Error('SAMPLE_TABLE environment variable is not set');
6170
}
6271

63-
const data = await docClient.send(new ScanCommand({
64-
TableName: tableName
65-
}));
72+
const data = await docClient.send(
73+
new ScanCommand({
74+
TableName: tableName,
75+
})
76+
);
6677
const { Items: items } = data;
6778

6879
// Logger: All log statements are written to CloudWatch
6980
logger.debug(`retrieved items: ${items?.length || 0}`);
70-
81+
7182
logger.info(`Response ${event.path}`, {
7283
statusCode: 200,
7384
body: items,
7485
});
7586

7687
return {
7788
statusCode: 200,
78-
body: JSON.stringify(items)
89+
body: JSON.stringify(items),
7990
};
8091
} catch (err) {
8192
tracer.addErrorAsMetadata(err as Error);
8293
logger.error('Error reading from table. ' + err);
83-
94+
8495
return {
8596
statusCode: 500,
86-
body: JSON.stringify({ 'error': 'Error reading from table.' })
97+
body: JSON.stringify({ error: 'Error reading from table.' }),
8798
};
8899
}
89100
};
@@ -95,4 +106,4 @@ export const handler = middy(getAllItemsHandler)
95106
// Use the middleware by passing the Logger instance as a parameter
96107
.use(injectLambdaContext(logger, { logEvent: true }))
97108
// Use the middleware by passing the Tracer instance as a parameter
98-
.use(captureLambdaHandler(tracer, { captureResponse: false })); // by default the tracer would add the response as metadata on the segment, but there is a chance to hit the 64kb segment size limit. Therefore set captureResponse: false
109+
.use(captureLambdaHandler(tracer, { captureResponse: false })); // by default the tracer would add the response as metadata on the segment, but there is a chance to hit the 64kb segment size limit. Therefore set captureResponse: false

examples/sam/src/get-by-id.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
1+
import {
2+
APIGatewayProxyEvent,
3+
APIGatewayProxyResult,
4+
Context,
5+
} from 'aws-lambda';
26
import { tableName } from './common/constants';
37
import { logger, tracer, metrics } from './common/powertools';
48
import { LambdaInterface } from '@aws-lambda-powertools/commons';
@@ -22,7 +26,6 @@ import { default as request } from 'phin';
2226
*/
2327

2428
class Lambda implements LambdaInterface {
25-
2629
@tracer.captureMethod()
2730
public async getUuid(): Promise<string> {
2831
// Request a sample random uuid from a webservice
@@ -37,11 +40,18 @@ class Lambda implements LambdaInterface {
3740

3841
@tracer.captureLambdaHandler({ captureResponse: false }) // by default the tracer would add the response as metadata on the segment, but there is a chance to hit the 64kb segment size limit. Therefore set captureResponse: false
3942
@logger.injectLambdaContext({ logEvent: true })
40-
@metrics.logMetrics({ throwOnEmptyMetrics: false, captureColdStartMetric: true })
41-
public async handler(event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult> {
42-
43+
@metrics.logMetrics({
44+
throwOnEmptyMetrics: false,
45+
captureColdStartMetric: true,
46+
})
47+
public async handler(
48+
event: APIGatewayProxyEvent,
49+
context: Context
50+
): Promise<APIGatewayProxyResult> {
4351
if (event.httpMethod !== 'GET') {
44-
throw new Error(`getById only accepts GET method, you tried: ${event.httpMethod}`);
52+
throw new Error(
53+
`getById only accepts GET method, you tried: ${event.httpMethod}`
54+
);
4555
}
4656

4757
// Tracer: Add awsRequestId as annotation
@@ -76,34 +86,35 @@ class Lambda implements LambdaInterface {
7686
if (!event.pathParameters.id) {
7787
throw new Error('PathParameter id is missing');
7888
}
79-
const data = await docClient.send(new GetCommand({
80-
TableName: tableName,
81-
Key: {
82-
id: event.pathParameters.id
83-
}
84-
}));
89+
const data = await docClient.send(
90+
new GetCommand({
91+
TableName: tableName,
92+
Key: {
93+
id: event.pathParameters.id,
94+
},
95+
})
96+
);
8597
const item = data.Item;
86-
98+
8799
logger.info(`Response ${event.path}`, {
88100
statusCode: 200,
89101
body: item,
90102
});
91-
103+
92104
return {
93105
statusCode: 200,
94-
body: JSON.stringify(item)
106+
body: JSON.stringify(item),
95107
};
96108
} catch (err) {
97109
tracer.addErrorAsMetadata(err as Error);
98110
logger.error('Error reading from table. ' + err);
99-
111+
100112
return {
101113
statusCode: 500,
102-
body: JSON.stringify({ 'error': 'Error reading from table.' })
114+
body: JSON.stringify({ error: 'Error reading from table.' }),
103115
};
104116
}
105117
}
106-
107118
}
108119

109120
const handlerClass = new Lambda();

0 commit comments

Comments
 (0)