Skip to content

Commit 3353586

Browse files
committed
treat cdk examples as any other modules
1 parent a7a91ad commit 3353586

21 files changed

+6861
-17229
lines changed

examples/cdk/bin/cdk-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import 'source-map-support/register';
33
import * as cdk from 'aws-cdk-lib';
4-
import { CdkAppStack } from '../lib/example-stack';
4+
import { CdkAppStack } from '../src/example-stack';
55

66
const app = new cdk.App();
77
new CdkAppStack(app, 'CdkAppStack', {});

examples/cdk/jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
testEnvironment: 'node',
3-
roots: ['<rootDir>/test'],
4-
testMatch: ['**/*.test.ts'],
3+
roots: ['<rootDir>/tests'],
4+
testMatch: ['**/*.tests.ts'],
55
transform: {
66
'^.+\\.tsx?$': 'ts-jest'
77
}

examples/cdk/package-lock.json

Lines changed: 6806 additions & 17177 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cdk/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "cdk-app",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"bin": {
55
"cdk-app": "bin/cdk-app.js"
66
},
77
"scripts": {
88
"build": "tsc --skipLibCheck",
99
"watch": "tsc -w",
10-
"test": "jest",
10+
"test": "jest --passWithNoTests",
1111
"cdk": "cdk"
1212
},
1313
"devDependencies": {

examples/cdk/lib/example-function.MyFunctionWithMiddy.ts renamed to examples/cdk/src/example-function.MyFunctionWithMiddy.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const metrics = new Metrics({ namespace: namespace, serviceName: serviceName });
1212
const logger = new Logger({ logLevel: 'INFO', serviceName: serviceName });
1313
const tracer = new Tracer({ serviceName: serviceName });
1414

15-
const lambdaHandler = async (event: typeof Events.Custom.CustomEvent, context: Context) => {
15+
const lambdaHandler = async (event: typeof Events.Custom.CustomEvent, context: Context): Promise<unknown> => {
1616
// ### Experiment with Logger
1717
// AWS Lambda context is automatically injected by the middleware
1818

@@ -32,7 +32,7 @@ const lambdaHandler = async (event: typeof Events.Custom.CustomEvent, context: C
3232
const metricWithItsOwnDimensions = metrics.singleMetric();
3333
metricWithItsOwnDimensions.addDimension('InnerDimension', 'true');
3434
metricWithItsOwnDimensions.addMetric('single-metric', MetricUnits.Percent, 50);
35-
35+
3636
// ### Experiment with Tracer
3737

3838
// Service & Cold Start annotations will be added for you by the decorator/middleware
@@ -58,16 +58,18 @@ const lambdaHandler = async (event: typeof Events.Custom.CustomEvent, context: C
5858
tracer.setSegment(handlerSegment);
5959
// The main segment (facade) will be closed for you at the end by the decorator/middleware
6060
}
61-
61+
6262
return res;
63-
}
63+
};
6464

6565
// We instrument the handler with the various Middy middlewares
6666
export const handler = middy(lambdaHandler)
6767
.use(captureLambdaHandler(tracer))
68-
.use(logMetrics(metrics, {
69-
captureColdStartMetric: true,
70-
throwOnEmptyMetrics: true,
71-
defaultDimensions: { environment: 'example', type: 'withDecorator' },
72-
}))
73-
.use(injectLambdaContext(logger));
68+
.use(
69+
logMetrics(metrics, {
70+
captureColdStartMetric: true,
71+
throwOnEmptyMetrics: true,
72+
defaultDimensions: { environment: 'example', type: 'withDecorator' },
73+
})
74+
)
75+
.use(injectLambdaContext(logger));

examples/cdk/lib/example-function.Tracer.Disabled.ts renamed to examples/cdk/src/example-function.Tracer.Disabled.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import { captureLambdaHandler, Tracer } from '@aws-lambda-powertools/tracer';
77
const tracer = new Tracer({ serviceName: 'tracerDisabledFn', enabled: false });
88

99
// In this example we are using the middleware pattern but the same applies also the captureLambdaHandler decorator or to manual instrumentation
10-
const lambdaHandler = async (event: typeof Events.Custom.CustomEvent, context: Context) => {
10+
const lambdaHandler = async (event: typeof Events.Custom.CustomEvent, context: Context): Promise<unknown> => {
1111
// No tracing will be done and the commands will be ignored, this is useful for testing
1212
tracer.putAnnotation('awsRequestId', context.awsRequestId);
1313
tracer.putMetadata('eventPayload', event);
14-
14+
1515
let res;
1616
try {
1717
res = { foo: 'bar' };
1818
} catch (err) {
1919
throw err;
2020
}
21-
21+
2222
return res;
23-
}
23+
};
2424

25-
export const handler = middy(lambdaHandler).use(captureLambdaHandler(tracer));
25+
export const handler = middy(lambdaHandler).use(captureLambdaHandler(tracer));

examples/cdk/lib/example-function.Tracer.Middleware.ts renamed to examples/cdk/src/example-function.Tracer.Middleware.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ const tracer = new Tracer({ serviceName: 'tracerMiddlewareFn' });
77
// Alternatively, you can also set the service name using the POWERTOOLS_SERVICE_NAME environment variable
88
// Learn more at: https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html
99

10-
const lambdaHandler = async (event: typeof Events.Custom.CustomEvent, context: Context) => {
10+
const lambdaHandler = async (event: typeof Events.Custom.CustomEvent, context: Context): Promise<unknown> => {
1111
// Add custom annotation & metadata
1212
tracer.putAnnotation('awsRequestId', context.awsRequestId);
1313
tracer.putMetadata('eventPayload', event);
14-
14+
1515
let res;
1616
try {
1717
res = { foo: 'bar' };
1818
} catch (err) {
1919
throw err;
2020
}
21-
21+
2222
return res;
23-
}
23+
};
2424

2525
// We instrument the handler with the Middy middleware and the Tracer will automatically:
2626
// * handle the lifecycle of the subsegment
2727
// * create a ColdStart annotation to easily filter traces that have had an initialization overhead
2828
// * create a Service annotation to easily filter traces that have a specific service name
2929
// * captures any response, or full exceptions generated by the handler, and include them as tracing metadata
30-
export const handler = middy(lambdaHandler).use(captureLambdaHandler(tracer));
30+
export const handler = middy(lambdaHandler).use(captureLambdaHandler(tracer));

examples/cdk/lib/example-function.ts renamed to examples/cdk/src/example-function.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ interface ExampleFunctionProps {
1212
}
1313

1414
class ExampleFunction extends Construct {
15-
public function: NodejsFunction;
1615

1716
public constructor(scope: Construct, id: string, props: ExampleFunctionProps) {
1817
super(scope, id);
File renamed without changes.

examples/cdk/test/cdk-app.test.ts renamed to examples/cdk/tests/cdk-app.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
// import { Template } from 'aws-cdk-lib/assertions';
33
// import * as CdkApp from '../lib/cdk-app-stack';
44

5-
test('It Deploys', () => {
6-
// TODO: implement tests
7-
});
5+
// test('It Deploys', () => {
6+
// // TODO: implement tests
7+
// });

examples/cdk/tsconfig.json

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2018",
3+
"experimentalDecorators": true,
4+
"noImplicitAny": true,
5+
"target": "ES2020",
46
"module": "commonjs",
5-
"skipLibCheck": true,
6-
"lib": [
7-
"es2018"
8-
],
97
"declaration": true,
8+
"outDir": "lib",
109
"strict": true,
11-
"noImplicitAny": true,
12-
"strictNullChecks": true,
13-
"noImplicitThis": true,
14-
"alwaysStrict": true,
15-
"noUnusedLocals": false,
16-
"noUnusedParameters": false,
17-
"noImplicitReturns": true,
18-
"noFallthroughCasesInSwitch": false,
1910
"inlineSourceMap": true,
20-
"inlineSources": true,
21-
"experimentalDecorators": true,
22-
"strictPropertyInitialization": false,
23-
"types": []
24-
},
25-
"exclude": [
26-
"node_modules",
27-
"cdk.out"
28-
]
11+
"moduleResolution": "node",
12+
"resolveJsonModule": true,
13+
"pretty": true,
14+
"baseUrl": "src/",
15+
"rootDirs": [ "src/" ],
16+
"esModuleInterop": true
17+
},
18+
"include": [ "src/**/*" ],
19+
"exclude": [ "./node_modules", "cdk.out"],
20+
"watchOptions": {
21+
"watchFile": "useFsEvents",
22+
"watchDirectory": "useFsEvents",
23+
"fallbackPolling": "dynamicPriority"
24+
},
25+
"lib": [ "es2020" ],
26+
"types": [
27+
"jest",
28+
"node"
29+
]
2930
}

lerna.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"packages": [
3-
"packages/*"
3+
"packages/*",
4+
"examples/cdk"
45
],
56
"version": "0.3.1",
67
"npmClient": "npm",

0 commit comments

Comments
 (0)