Skip to content
This repository was archived by the owner on Sep 8, 2022. It is now read-only.

chore: simplified examples #15

Merged
merged 2 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
124 changes: 0 additions & 124 deletions API.md

This file was deleted.

48 changes: 7 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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:
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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):
Expand All @@ -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';
Expand Down
10 changes: 5 additions & 5 deletions src/lambda-powertools-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'.
*
*/
Expand Down