Skip to content

Commit df65b1f

Browse files
committed
Auto lint and build examples
1 parent 4cdaaea commit df65b1f

24 files changed

+9627
-17233
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,30 @@ You can run the end-to-end tests automatically on your forked project by followi
147147
4. In the run-e2e-tests workflow page, select "Run workflow" and run it on the desired branch.
148148

149149
> :warning: **Don't automatically run end-to-end tests on branch push or PRs**. A malicious attacker can submit a pull request to attack your AWS account. Ideally, use a blank account without any important workload/data, and limit `AWS_ROLE_ARN_TO_ASSUME` permission to least minimum privilege.
150+
151+
152+
### Examples
153+
154+
As part of the repo you will find an examples folder at the root. This folder contains examples (written with CDK for now) of deployable AWS Lambda functions using Powertools.
155+
156+
To test your updates with these examples you just have to:
157+
158+
1. Build your local version of *aws-lambda-powertools-typescript* npm packages with `npm run lerna-package`
159+
1. Update their references in examples
160+
```
161+
cd examples/cdk
162+
npm install ../../packages/**/dist/aws-lambda-powertools-*
163+
```
164+
1. Run cdk tests
165+
```
166+
npm run test
167+
```
168+
1. Deploy
169+
```
170+
npm run cdk deploy
171+
```
172+
173+
Previous command will deploy AWS resources therefore you will need an AWS account and it might incur in some costs which should be covered by the [AWS Free Tier](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank&all-free-tier.sort-order=asc&awsf.Free%20Tier%20Types=*all&awsf.Free%20Tier%20Categories=*all). If you don't have an AWS Account follow [these instructions to create one](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/).
150174
### Conventions
151175
152176
Category | Convention

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
testEnvironment: 'node',
3-
roots: ['<rootDir>/test'],
3+
roots: ['<rootDir>/tests'],
44
testMatch: ['**/*.test.ts'],
55
transform: {
66
'^.+\\.tsx?$': 'ts-jest'

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": "npm run build && jest",
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));

0 commit comments

Comments
 (0)