JSPM

cdk-http-openapi

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q32672F
  • License MIT

CDK Construct that lets you build AWS Api Gateway Http Api, backed by Lambdas, based on a OpenAPI spec file.

Package Exports

  • cdk-http-openapi
  • cdk-http-openapi/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cdk-http-openapi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

cdk-http-openapi

CDK Construct that lets you build AWS Api Gateway Http Api, backed by Lambdas, based on a OpenAPI spec file.

Features

[] Deploy Api Gateway Http Api based on a OpenAPI spec file. [] Each API Route will be backed by 1 NodeJS lambda. [] Configure CORS for your API. [] Add custom domain (eg: https://my-awesome-api.my-domain.com) to your API. [] Enable custom authorizers to Http Api Lambda integrations. [] Customize your lambdas's memory, timeouts, log retention, env variables and other stuff.

Setup

Add latest package to your project with npm/yarn

npm i --save cdk-http-openapi
yarn add -D cdk-http-openapi

Start using cdk constructs in your infrastructure definition
Examples

import { HttpOpenApi } from 'cdk-http-openapi'

// ... in your stack definition
const api = new HttpOpenApi(this, 'MyApi', {
    serviceName: 'my-service',
    openApiSpec: './openapi.yml',
    lambdasSourcePath: './dist/src' // optional. It defaults to './.build/src'
    integrations: [
        {
            operationId: 'getEntity', // for each operation you define in your OpenAPI spec
            handler: 'api.getEntity', // you can register a lambda handler to handle your http request
        },
        {
            operationId: 'storeEntity',
            handler: 'api.storeEntity',
            timeoutSeconds: 5,
            memorySize: 512,
            env: { 
                DB_HOST: '...',
                DB_USERNAME: '...',
                DB_PASSWORD: '...'
            },
        }
    ]
});

const domainName = 'my-awesome-api.cool.io';
const certificateArn = `arn:aws:acm:${AWS_REGION}:${AWS_ACCOUNT}:certificate/${CERTIFICATE_ID}`;
const hostedZone = 'cool.io';

api.enableCustomDomain({domainName, certificateArn, hostedZone});