2.11.16 • Published 5 days ago

cdk-serverless v2.11.16

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 days ago

CDK Serverless

npm version

CDK Serverless is a tool suite to facilitate the use of the AWS Cloud Development Kit (CDK) in serverless architectures. It provides project management features to configure your TypeScript CDK app and also higher-level (L3) constructs for different APIs and resources needed for serverless applications. Additionally, it leverages utility libraries to write Lambda functions and do live updates to Lambda function code during development.

Features

  • Projen helper classes to configure certain use cases easily
  • AWS CDK L3-construct for HttpApi and GraphQlApi
  • Zero-config for Lambda functions and VTL templates
  • Live update to Lambda function code using cdk-watch
  • Automatic DynamoDB SingleTable infrastructure
  • Automatic monitoring added for Lambda functions and APIs
  • Full features of CDK usable to implement your special use cases
  • Fully typed auto-completion for routes, resolvers, etc.

Short intro video: https://www.youtube.com/watch?v=GGc0eg3E9MM

Quick Start

To start a new project we recommend using projen. To use CDK Serverless you can create any projen CDK Typescript app and then add the appropriate aspect provided by this toolkit.

$ npx projen new awscdk-app-ts

Adding CDK Serverless is a two step process:

  1. Add 'cdk-serverless' as a dependency to your project
  2. Run npx projen to install it

You can then add the 'GraphQlApiAspect' or the 'HttpApiAspect' depending on your desired API type.

.projenrc.js:

// Import cdk-serverless projen aspects
const { HttpApiAspect } = require('cdk-serverless/lib/projen');
const { AwsCdkTypeScriptApp } = require('projen');

const project = new AwsCdkTypeScriptApp({
  cdkVersion: '1.91.0',
  cdkVersionPinning: true,
  defaultReleaseBranch: 'main',
  name: 'cdk-serverless-demo',
  deps: [
    // Add cdk-serverless as dependency
    'cdk-serverless',
  ],
});

// Add HTTP API Support
new HttpApiAspect(project, {
  cdkWatch: {
    // Add live update scripts using CDK Watch
    dev: 'my-http-stack-dev/**',
  },
});

project.synth();

This will install all the necessary dependencies and register some scripts like generate:api to generate type definitions from the openapi.yaml and live:dev to watch for code changes and redeploy the Lambda function code.

Replace the content of file openapi.yaml with your OpenAPI definition and run yarn generate:api to generate type definitions. An example OpenAPI file is available in the demo project.

IMPORTANT! cdk-serverless needs an operationId field on every operation in the openapi.yaml

OpenAPI 3.0 or higher is supported in openapi.yaml. The content type for request- and response-body is currently limited to application/json.

After this you can add the selected L3 construct to your CDK app and configure it depending on your needs.

src/main.js:

import { HttpApi } from 'cdk-serverless/lib/constructs';
// Import the generated Path and Operation information
import { paths, operations } from './lambda/types.generated';

// Create a new HTTP API
const api = new HttpApi<paths, operations>(this, 'Api', {
  // Name of the API in the AWS console
  apiName: 'testapi',
  // This will be prefixed with 'api.' by default and will lead to https://api.taimos.de
  domainName: 'taimos.de',
  // Name of the stage in a multi-stage deployment
  stageName: 'dev',
  // Automatically create a DynamoDB table and configure a global secondary index
  // HashKey will be 'PK' and SortKey will be 'SK'
  singleTableDatastore: {
    design: {
      // Create an inverted GSI with 'SK' as HashKey and 'PK' as SortKey
      reverseGSI: true,
    },
  },
  // Add a Cognito user pool with two groups and a trigger to customize welcome e-mails
  authentication: {
    groups: {
      admin: 'Admins',
      moderators: 'Mods',
    },
    triggers: {
      customMessages: true,
    },
  },
  // automatically generate lambda functions for all routes in openapi.yaml (true by default)
  autoGenerateRoutes: true,
  // Create a CloudWatch Dashboard to monitor the API and all Lambda functions (true by default)
  monitoring: true,
});

On the first cdk synth this will automatically bootstrap all lambda code files that are not yet existing. If you want to modify Lambda function definitions you can access them by calling:

api.getFunctionForOperation('operationId').doSomething()

This operation id supports autocompletion using the generated type definitions.

Autocomplete

DynamoDB SingleTable

If enabled a Single-Table Design DynamoDB table will be created.

Permissions

All functions have read permissions, regardless of which operation they are bound to. Only functions bound to a DELETE, POST, PUT or PATCH operation will have write permissions.

Docs Links

Constructs

Tools

Contribute

How to contribute to CDK Serverless

Did you find a bug?

  • Ensure the bug was not already reported by searching on GitHub under Issues.

  • If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a title and clear description, as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behavior that is not occurring.

Did you write a patch that fixes a bug?

  • Open a new GitHub pull request with the patch.

  • Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.

Did you fix whitespace, format code, or make a purely cosmetic patch?

Changes that are cosmetic in nature and do not add anything substantial to the stability, functionality, or testability will normally not be accepted.

Do you intend to add a new feature or change an existing one?

  • Suggest your change under Issues.

  • Do not open a pull request on GitHub until you have collected positive feedback about the change.

Do you want to contribute to the CDK Serverless documentation?

  • Just file a PR with your recommended changes

Authors

Brought to you by Taimos

2.11.16

5 days ago

2.11.15

12 days ago

2.11.14

19 days ago

2.11.13

26 days ago

2.11.12

1 month ago

2.11.11

1 month ago

2.11.10

1 month ago

2.11.9

2 months ago

2.11.8

2 months ago

2.11.7

2 months ago

2.11.6

2 months ago

2.11.5

3 months ago

2.11.4

3 months ago

2.11.3

3 months ago

2.11.1

3 months ago

2.11.2

3 months ago

2.11.0

3 months ago

2.10.2

3 months ago

2.10.1

3 months ago

2.10.0

4 months ago

2.9.2

4 months ago

2.9.1

4 months ago

2.9.0

4 months ago

2.8.0

4 months ago

2.4.3

9 months ago

2.4.2

10 months ago

2.7.0

6 months ago

2.6.1

8 months ago

2.6.0

8 months ago

2.6.2

8 months ago

2.5.0

8 months ago

2.4.1

10 months ago

2.4.0

10 months ago

2.3.0

10 months ago

2.3.1

10 months ago

2.2.1

10 months ago

2.2.0

10 months ago

2.2.2

10 months ago

2.1.0

11 months ago

2.0.3

11 months ago

2.0.2

12 months ago

2.0.4

11 months ago

2.0.1

1 year ago

2.0.0

1 year ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.30

2 years ago

1.1.34

2 years ago

1.1.33

2 years ago

1.1.32

2 years ago

1.1.31

2 years ago

1.1.38

2 years ago

1.1.37

2 years ago

1.1.36

2 years ago

1.1.35

2 years ago

1.1.39

2 years ago

1.1.41

2 years ago

1.1.40

2 years ago

1.1.44

2 years ago

1.1.43

2 years ago

1.1.42

2 years ago

1.1.27

2 years ago

1.1.26

2 years ago

1.1.25

2 years ago

1.1.12

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.1.24

2 years ago

1.0.80

2 years ago

1.0.84

2 years ago

1.0.83

2 years ago

1.0.82

2 years ago

1.0.81

2 years ago

1.0.88

2 years ago

1.0.87

2 years ago

1.0.86

2 years ago

1.0.85

2 years ago

1.0.89

2 years ago

1.0.91

2 years ago

1.0.90

2 years ago

1.0.69

2 years ago

1.0.73

2 years ago

1.0.72

2 years ago

1.0.71

2 years ago

1.0.70

2 years ago

1.0.77

2 years ago

1.0.76

2 years ago

1.0.75

2 years ago

1.0.74

2 years ago

1.0.79

2 years ago

1.0.78

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.0.62

2 years ago

1.0.61

2 years ago

1.0.66

2 years ago

1.0.65

2 years ago

1.0.64

2 years ago

1.0.63

2 years ago

1.0.68

2 years ago

1.0.67

2 years ago

0.1.53

2 years ago

1.0.60

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.40

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.48

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.49

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.55

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.59

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.19

2 years ago

1.0.2

2 years ago

1.0.18

2 years ago

1.0.1

2 years ago

1.0.17

2 years ago

1.0.0

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

0.1.52

2 years ago

0.1.51

2 years ago

0.1.50

3 years ago

0.1.49

3 years ago

0.1.47

3 years ago

0.1.48

3 years ago

0.1.46

3 years ago

0.1.45

3 years ago

0.1.43

3 years ago

0.1.44

3 years ago

0.1.41

3 years ago

0.1.42

3 years ago

0.1.40

3 years ago

0.1.38

3 years ago

0.1.39

3 years ago

0.1.30

3 years ago

0.1.31

3 years ago

0.1.32

3 years ago

0.1.33

3 years ago

0.1.34

3 years ago

0.1.35

3 years ago

0.1.36

3 years ago

0.1.37

3 years ago

0.1.27

3 years ago

0.1.28

3 years ago

0.1.29

3 years ago

0.1.25

3 years ago

0.1.26

3 years ago

0.1.10

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.9

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.20

3 years ago

0.1.21

3 years ago

0.1.22

3 years ago

0.1.23

3 years ago

0.1.24

3 years ago

0.1.16

3 years ago

0.1.17

3 years ago

0.1.18

3 years ago

0.1.19

3 years ago

0.1.0

3 years ago

0.1.2

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.0.59

3 years ago

0.0.57

3 years ago

0.0.58

3 years ago

0.0.56

3 years ago

0.0.55

3 years ago

0.0.52

3 years ago

0.0.53

3 years ago

0.0.54

3 years ago

0.0.47

3 years ago

0.0.51

3 years ago

0.0.50

3 years ago

0.0.48

3 years ago

0.0.49

3 years ago

0.0.45

3 years ago

0.0.46

3 years ago

0.0.40

3 years ago

0.0.41

3 years ago

0.0.42

3 years ago

0.0.43

3 years ago

0.0.44

3 years ago

0.0.38

3 years ago

0.0.39

3 years ago

0.0.37

3 years ago

0.0.32

3 years ago

0.0.33

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.36

3 years ago

0.0.30

3 years ago

0.0.31

3 years ago

0.0.27

3 years ago

0.0.28

3 years ago

0.0.29

3 years ago

0.0.25

3 years ago

0.0.26

3 years ago

0.0.24

3 years ago

0.0.23

3 years ago

0.0.22

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.19

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.16

3 years ago

0.0.13

3 years ago

0.0.14

3 years ago

0.0.15

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.4

3 years ago