Skip to content

Commit 85082b6

Browse files
committed
Merge remote-tracking branch 'origin/main' into chore/cicd/examplesTests
2 parents 16aeb07 + 646a9e8 commit 85082b6

File tree

7 files changed

+30
-19
lines changed

7 files changed

+30
-19
lines changed

Diff for: docs/core/logger.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,13 @@ This is how the `MyCompanyLogFormatter` (dummy name) would look like:
625625
=== "utils/formatters/MyCompanyLogFormatter.ts"
626626

627627
```typescript
628-
import { LogFormatter } from "@aws-lambda-powertools/logger";
629-
import { LogAttributes, UnformattedAttributes } from "@aws-lambda-powertools/logger/types";
628+
import { LogFormatter } from '@aws-lambda-powertools/logger';
629+
import { LogAttributes, UnformattedAttributes } from '@aws-lambda-powertools/logger/lib/types';
630630

631631
// Replace this line with your own type
632632
type MyCompanyLog = LogAttributes;
633633

634-
class MyCompanyLogFormatter implements LogFormatter {
634+
class MyCompanyLogFormatter extends LogFormatter {
635635

636636
public formatAttributes(attributes: UnformattedAttributes): MyCompanyLog {
637637
return {

Diff for: examples/cdk/README.md

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
# Welcome to your CDK TypeScript project!
1+
# AWS Lambda Powertools (TypeScript) examples in CDK
22

3-
This is a blank project for TypeScript development with CDK.
3+
This is a deployable CDK app that deploys AWS Lambda functions as part of a CloudFormation stack. These Lambda functions use the utilities made available as part of AWS Lambda Powertools (TypeScript) to demonstrate their usage.
44

5-
The `cdk.json` file tells the CDK Toolkit how to execute your app.
5+
You will need to have a valid AWS Account in order to deploy these resources. These resources may incur costs to your AWS Account. The cost from **some services** are 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) but not all of them. 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/).
66

7-
## Useful commands
7+
The example functions, located in the `lib` folder, are invoked automatically, twice, when deployed using the CDK construct defined in `lib/example-function.ts`. The first invocation demonstrates the effect on logs/metrics/annotations when the Lambda function has a cold start, and the latter without a cold start.
88

9-
* `npm run build` compile typescript to js
10-
* `npm run watch` watch for changes and compile
11-
* `npm run test` perform the jest unit tests
12-
* `cdk deploy` deploy this stack to your default AWS account/region
13-
* `cdk diff` compare deployed stack with current state
14-
* `cdk synth` emits the synthesized CloudFormation template
9+
## Deploying the stack
10+
11+
* Ensure that CDK v2 is installed globally on your machine (if not, run `npm install -g aws-cdk`)
12+
* Navigate to this location of the repo in your terminal (`examples/cdk`)
13+
* `npm install`
14+
* `cdk deploy --all --profile <YOUR_AWS_PROFILE>`
15+
16+
Note: Prior to deploying you may need to run `cdk bootstrap aws://<YOU_AWS_ACCOUNT_ID>/<AWS_REGION> --profile <YOUR_AWS_PROFILE>` if you have not already bootstrapped your account for CDK.
17+
18+
## Viewing Utility Outputs
19+
20+
All utility outputs can be viewed in the Amazon CloudWatch console.
21+
22+
* `Logger` output can be found in Logs > Log groups
23+
* `Metrics` output can be found in Metrics > All metrics > CdkExample
24+
* `Tracer` output can be found in X-Ray traces > Traces

Diff for: examples/cdk/bin/cdk-app.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ import * as cdk from 'aws-cdk-lib';
44
import { CdkAppStack } from '../src/example-stack';
55

66
const app = new cdk.App();
7-
new CdkAppStack(app, 'CdkAppStack', {});
7+
new CdkAppStack(app, 'LambdaPowertoolsTypeScript-ExamplesCdkStack', {});

Diff for: packages/logger/src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './helpers';
22
export * from './Logger';
3-
export * from './middleware';
3+
export * from './middleware';
4+
export * from './formatter';

Diff for: packages/metrics/src/Metrics.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class Metrics implements MetricsInterface {
210210
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
211211
* import { Callback, Context } from 'aws-lambda';
212212
*
213-
* const metrics = new Metrics({namespace:"CDKExample", serviceName:"withDecorator"});
213+
* const metrics = new Metrics({namespace:"CdkExample", serviceName:"withDecorator"});
214214
*
215215
* export class MyFunctionWithDecorator {
216216
*
@@ -267,7 +267,7 @@ class Metrics implements MetricsInterface {
267267
* ```typescript
268268
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
269269
*
270-
* const metrics = new Metrics({namespace: "CDKExample", serviceName: "MyFunction"}); // Sets metric namespace, and service as a metric dimension
270+
* const metrics = new Metrics({namespace: "CdkExample", serviceName: "MyFunction"}); // Sets metric namespace, and service as a metric dimension
271271
*
272272
* export const handler = async (_event: any, _context: any) => {
273273
* metrics.addMetric('test-metric', MetricUnits.Count, 10);

Diff for: packages/metrics/tests/e2e/decorator.test.MyFunction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Metrics, MetricUnits } from '../../src';
22
import { Context } from 'aws-lambda';
33
import { LambdaInterface } from '../../examples/utils/lambda/LambdaInterface';
44

5-
const namespace = process.env.EXPECTED_NAMESPACE ?? 'CDKExample';
5+
const namespace = process.env.EXPECTED_NAMESPACE ?? 'CdkExample';
66
const serviceName = process.env.EXPECTED_SERVICE_NAME ?? 'MyFunctionWithStandardHandler';
77
const metricName = process.env.EXPECTED_METRIC_NAME ?? 'MyMetric';
88
const metricUnit = (process.env.EXPECTED_METRIC_UNIT as MetricUnits) ?? MetricUnits.Count;

Diff for: packages/metrics/tests/e2e/standardFunctions.test.MyFunction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Metrics, MetricUnits } from '../../src';
22
import { Context } from 'aws-lambda';
33

4-
const namespace = process.env.EXPECTED_NAMESPACE ?? 'CDKExample';
4+
const namespace = process.env.EXPECTED_NAMESPACE ?? 'CdkExample';
55
const serviceName = process.env.EXPECTED_SERVICE_NAME ?? 'MyFunctionWithStandardHandler';
66
const metricName = process.env.EXPECTED_METRIC_NAME ?? 'MyMetric';
77
const metricUnit = (process.env.EXPECTED_METRIC_UNIT as MetricUnits) ?? MetricUnits.Count;

0 commit comments

Comments
 (0)