From b699805a1964b4c9cb23422ee91a42446f44011c Mon Sep 17 00:00:00 2001 From: Alexander Melnyk Date: Wed, 12 Jan 2022 10:58:44 +0100 Subject: [PATCH 1/2] docs: simplified examples --- README.md | 48 +++++----------------------------- src/lambda-powertools-layer.ts | 10 +++---- 2 files changed, 12 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index afed33f..ddd99f4 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ and add it to your function. The construct is an extension of the existing [`LayerVersion`](https://docs.aws.amazon.com/cdk/api/v1/docs/@aws-cdk_aws-lambda.LayerVersion.html) construct from the CDK library, so you have access to all fields and methods. +See the [API](API.md) for details. + ```typescript import { LambdaPowertoolsLayer } from 'cdk-lambda-powertools-python-layer'; @@ -23,6 +25,8 @@ from cdk_lambda_powertools_python_layer import LambdaPowertoolsLayer powertoolsLayer = LambdaPowertoolsLayer(self, 'PowertoolsLayer') ``` +The layer will be created during the CDK `synth` step and thus requires Docker. + ## Install TypeSript/JavaScript: @@ -52,6 +56,8 @@ powertoolsLayer = LambdaPowertoolsLayer(self, 'PowertoolsLayer') You can then add the layer to your funciton: ```python +from aws_cdk import aws_lambda + aws_lambda.Function(self, 'LambdaFunction', code=aws_lambda.Code.from_asset('function'), handler='app.handler', @@ -80,7 +86,6 @@ Full example: from aws_cdk import Stack, aws_lambda from cdk_lambda_powertools_python_layer import LambdaPowertoolsLayer from constructs import Construct -from typing_extensions import runtime class LayerTestStack(Stack): @@ -101,46 +106,7 @@ class LayerTestStack(Stack): ### TypeScript -These examples are for TypeScript: - -Build the layer: - -```typescript -import { LambdaPowertoolsLayer } from 'cdk-lambda-powertools-python-layer'; - -const powertoolsLayer = new LambdaPowertoolsLayer(this, 'TestLayer', { - version: '1.22.0', -}); -``` - -Add to your function: - -```typescript -new Function(this, 'LambdaFunction', { - code: Code.fromAsset(path.join('./function')), - handler: 'app.handler', - runtime: Runtime.PYTHON_3_9, - layers: [powertoolsLayer], -}); -``` - -You can specify the powertools version: - -```typescript -new LambdaPowertoolsLayer(this, 'PowertoolsLayer', { - version: '1.21.0' -}); -``` - -Decide if you want to incldue pydantic as extras dependencies: - -```typescript -new LambdaPowertoolsLayer(this, 'PowertoolsLayer', { - includeExtras: true -}); -``` - -Full example: +Full example for TypeScript: ```typescript import { Stack, StackProps } from 'aws-cdk-lib'; diff --git a/src/lambda-powertools-layer.ts b/src/lambda-powertools-layer.ts index f85cc0d..e29ee67 100644 --- a/src/lambda-powertools-layer.ts +++ b/src/lambda-powertools-layer.ts @@ -3,15 +3,15 @@ import { aws_lambda as lambda } from 'aws-cdk-lib'; import { Construct } from 'constructs'; /** - * Properties necessary to create Powertools layer for python. + * Properties for Powertools layer for python. */ export interface PowertoolsLayerProps { /** - * The powertools package version form pypi repository. + * The powertools package version from pypi repository. */ readonly version?: string; /** - * A flag to decide wether to include the extras package, used for parsing. + * A flag for the pydantic extras dependency, used for parsing. * This will increase the size of the layer significantly. If you don't use parsing, ignore it. */ readonly includeExtras?: boolean; @@ -25,9 +25,9 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion { /** * creates build argument for the Dockerfile. - * We have multiple combinations between version and extras package that results in different suffix for the installation. + * There are multiple combinations between version and extras package that results in different suffix for the installation. * With and without version, with and without extras flag. - * We construct one suffix here because it is easier to do than inside the Dockerfile with bash commands. + * We construct one suffix here because it is easier to do in code than inside the Dockerfile with bash commands. * For example, if we set extras=true and version=1.22.0 we get '[pydantic]==1.22.0'. * */ From e0f0480154e6101dbfd76aa9c3aab4f47ab4d5f1 Mon Sep 17 00:00:00 2001 From: Alexander Melnyk Date: Wed, 12 Jan 2022 11:08:41 +0100 Subject: [PATCH 2/2] chore: remove API.md, it should be generated --- API.md | 124 --------------------------------------------------------- 1 file changed, 124 deletions(-) delete mode 100644 API.md diff --git a/API.md b/API.md deleted file mode 100644 index 14c7821..0000000 --- a/API.md +++ /dev/null @@ -1,124 +0,0 @@ -# API Reference - -## Constructs - -### LambdaPowertoolsLayer - -Defines a new Lambda Layer with Powertools for python library. - -#### Initializers - -```typescript -import { LambdaPowertoolsLayer } from 'cdk-lambda-powertools-python-layer' - -new LambdaPowertoolsLayer(scope: Construct, id: string, props?: PowertoolsLayerProps) -``` - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| [`scope`](#cdklambdapowertoolspythonlayerlambdapowertoolslayerparameterscope)* | [`constructs.Construct`](#constructs.Construct) | *No description.* | -| [`id`](#cdklambdapowertoolspythonlayerlambdapowertoolslayerparameterid)* | `string` | *No description.* | -| [`props`](#cdklambdapowertoolspythonlayerlambdapowertoolslayerparameterprops) | [`cdk-lambda-powertools-python-layer.PowertoolsLayerProps`](#cdk-lambda-powertools-python-layer.PowertoolsLayerProps) | *No description.* | - ---- - -##### `scope`Required - -- *Type:* [`constructs.Construct`](#constructs.Construct) - ---- - -##### `id`Required - -- *Type:* `string` - ---- - -##### `props`Optional - -- *Type:* [`cdk-lambda-powertools-python-layer.PowertoolsLayerProps`](#cdk-lambda-powertools-python-layer.PowertoolsLayerProps) - ---- - - -#### Static Functions - -| **Name** | **Description** | -| --- | --- | -| [`constructBuildArgs`](#cdklambdapowertoolspythonlayerlambdapowertoolslayerconstructbuildargs) | creates build argument for the Dockerfile. | - ---- - -##### `constructBuildArgs` - -```typescript -import { LambdaPowertoolsLayer } from 'cdk-lambda-powertools-python-layer' - -LambdaPowertoolsLayer.constructBuildArgs(includeExtras?: boolean, version?: string) -``` - -###### `includeExtras`Optional - -- *Type:* `boolean` - ---- - -###### `version`Optional - -- *Type:* `string` - ---- - - - -## Structs - -### PowertoolsLayerProps - -Properties necessary to create Powertools layer for python. - -#### Initializer - -```typescript -import { PowertoolsLayerProps } from 'cdk-lambda-powertools-python-layer' - -const powertoolsLayerProps: PowertoolsLayerProps = { ... } -``` - -#### Properties - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| [`includeExtras`](#cdklambdapowertoolspythonlayerpowertoolslayerpropspropertyincludeextras) | `boolean` | A flag to decide wether to include the extras package, used for parsing. | -| [`version`](#cdklambdapowertoolspythonlayerpowertoolslayerpropspropertyversion) | `string` | The powertools package version form pypi repository. | - ---- - -##### `includeExtras`Optional - -```typescript -public readonly includeExtras: boolean; -``` - -- *Type:* `boolean` - -A flag to decide wether to include the extras package, used for parsing. - -This will increase the size of the layer significantly. If you don't use parsing, ignore it. - ---- - -##### `version`Optional - -```typescript -public readonly version: string; -``` - -- *Type:* `string` - -The powertools package version form pypi repository. - ---- - - -