Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Improve examples/cdk/README.md #467

Merged
merged 3 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions examples/cdk/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# Welcome to your CDK TypeScript project!
# AWS Lambda Powertools (TypeScript) examples in CDK

This is a blank project for TypeScript development with CDK.
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.

The `cdk.json` file tells the CDK Toolkit how to execute your app.
The example functions, located in the `lib` folder, are triggered automatically when deployed using the CDK construct defined in `lib/example-function.ts`.
dreamorosi marked this conversation as resolved.
Show resolved Hide resolved

## Useful commands
## Deploying the stack

* `npm run build` compile typescript to js
* `npm run watch` watch for changes and compile
* `npm run test` perform the jest unit tests
* `cdk deploy` deploy this stack to your default AWS account/region
* `cdk diff` compare deployed stack with current state
* `cdk synth` emits the synthesized CloudFormation template
* Navigate to this location of the repo in your terminal (`examples/cdk`)
* `npm install`
* `npx cdk deploy --all --profile <YOUR_AWS_PROFILE>`

Note: Prior to deploying you may need to run `npx cdk bootstrap aws://<YOU_AWS_ACCOUNT_ID>/<AWS_REGION> --profile <YOUR_AWS_PROFILE>` if you have not already bootstrapped your account for CDK.
dreamorosi marked this conversation as resolved.
Show resolved Hide resolved

dreamorosi marked this conversation as resolved.
Show resolved Hide resolved
## Viewing Utility Outputs

All utility outputs can be viewed from the CloudWatch console.
dreamorosi marked this conversation as resolved.
Show resolved Hide resolved

* `Logger` outputs to Logs > Log groups
* `Metrics` outputs to Metrics > All metrics > LambdaPowertoolsTypeScript-CDKExample
* `Tracer` outputs to X-Ray traces > Traces
dreamorosi marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion examples/cdk/bin/cdk-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import * as cdk from 'aws-cdk-lib';
import { CdkAppStack } from '../lib/example-stack';

const app = new cdk.App();
new CdkAppStack(app, 'CdkAppStack', {});
new CdkAppStack(app, 'LambdaPowertoolsTypeScript-ExamplesCdkStack', {});
4 changes: 2 additions & 2 deletions packages/metrics/src/Metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Metrics implements MetricsInterface {
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
* import { Callback, Context } from 'aws-lambda';
*
* const metrics = new Metrics({namespace:"CDKExample", serviceName:"withDecorator"});
* const metrics = new Metrics({namespace:"LambdaPowertoolsTypeScript-CDKExample", serviceName:"withDecorator"});
*
* export class MyFunctionWithDecorator {
*
Expand Down Expand Up @@ -267,7 +267,7 @@ class Metrics implements MetricsInterface {
* ```typescript
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
*
* const metrics = new Metrics({namespace: "CDKExample", serviceName: "MyFunction"}); // Sets metric namespace, and service as a metric dimension
* const metrics = new Metrics({namespace: "LambdaPowertoolsTypeScript-CDKExample", serviceName: "MyFunction"}); // Sets metric namespace, and service as a metric dimension
*
* export const handler = async (_event: any, _context: any) => {
* metrics.addMetric('test-metric', MetricUnits.Count, 10);
Expand Down
2 changes: 1 addition & 1 deletion packages/metrics/tests/e2e/decorator.test.MyFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Metrics, MetricUnits } from '../../src';
import { Context } from 'aws-lambda';
import { LambdaInterface } from '../../examples/utils/lambda/LambdaInterface';

const namespace = process.env.EXPECTED_NAMESPACE ?? 'CDKExample';
const namespace = process.env.EXPECTED_NAMESPACE ?? 'LambdaPowertoolsTypeScript-CDKExample';
alex-m-aws marked this conversation as resolved.
Show resolved Hide resolved
const serviceName = process.env.EXPECTED_SERVICE_NAME ?? 'MyFunctionWithStandardHandler';
const metricName = process.env.EXPECTED_METRIC_NAME ?? 'MyMetric';
const metricUnit = (process.env.EXPECTED_METRIC_UNIT as MetricUnits) ?? MetricUnits.Count;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Metrics, MetricUnits } from '../../src';
import { Context } from 'aws-lambda';

const namespace = process.env.EXPECTED_NAMESPACE ?? 'CDKExample';
const namespace = process.env.EXPECTED_NAMESPACE ?? 'LambdaPowertoolsTypeScript-CDKExample';
alex-m-aws marked this conversation as resolved.
Show resolved Hide resolved
const serviceName = process.env.EXPECTED_SERVICE_NAME ?? 'MyFunctionWithStandardHandler';
const metricName = process.env.EXPECTED_METRIC_NAME ?? 'MyMetric';
const metricUnit = (process.env.EXPECTED_METRIC_UNIT as MetricUnits) ?? MetricUnits.Count;
Expand Down