1.7.0 • Published 4 months ago

aws-typescript-toolkit v1.7.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

AWS Typescript Toolkit

Common utils, types, exceptions, constants and services

Features:

  • Base handler for lamba resource
  • Common:
    • Utils
    • Types
    • Services
    • Exceptions:
      • Backend Error
      • Database Error
    • Config
      • getConfig()
        • VERSION
        • DEPLOYMENT_NAME
        • TABLE_NAME
        • PLATFORM_PREFIX

Installation

yarn install aws-typescript-toolkit

Exports

import { Services, BaseHandler, Constants, Construct, Exceptions, Types, Utils } from 'aws-typescript-toolkit';

const { Bucket, DeepLink, Dynamodb, Event, Logger, SSM } = Service;
const { createConstructs, setResources, ConstructMiddleware } = Construct;
const { BaseError, BackendError, DatabaseError } = Exceptions;
const { createFileNameHandler, streamToString, flattenInput, constructName, generateName, getConstructs } = Utils;
const { ValueOf, IAWSLambdaHandler, GqlInput, StackProps, ConstructTypes, IConstruct, INewConstruct, Callback, GenericExtend, gql } = Types;
const { getConfig } = Config;

const { VERSION, DEPLOYMENT_NAME, PLATFORM_PREFIX, TABLE_NAME } = getConfig();

Construct

Utilities to simplify setting up of constructs.

  • createConstructs

Usage is similar to createSlice from Redux Toolkit.

// cdk/constructs/lambda/EntityName.ts

import { Construct, Services, Config } from 'aws-typescript-toolkit'

const { createConstructs } = Construct;
const { SSMActions } = Services.SSM
const { getConfig } = Config;

const { TABLE_NAME } = getConfig();

const EntityName = createConstructs({
  type: NodejsFunction,
  constructs: {
    handleHelloWorld: {
      props: { 
        environment: { TABLE_NAME } 
      }, 
      output: true,
      callback: async (scope, construct) => {
        // Add event source trigger
        const eventBusArn = Fn.importValue('EventsPlatform-EventBus');
        const eventBus = EventBus.fromEventBusArn(scope, 'ImportedEventBus', eventBusArn);
        eventBus.grantPutEventsTo(construct);

        // Fetch param store
        const ssmClient = new SSMActions();
        const parameterInput = {
          Name: `/${DEPLOYMENT_NAME}/key`,
        };
        const parameter = await ssmClient.getParameter(parameterInput);

        // Add Environments
        construct.addEnvironment('BRANCH_KEY', parameter?.Value ?? '');
        construct.addEnvironment('EVENT_BUS_NAME', eventBus.eventBusName);
      },
    },
  },
});

export const { handleHelloWorld } = EntityName;

Config

Gets the config file of the cdk project platform.json.

Expected Content

{
  "name": "cdk-project-name",
  "version": "1.0.0",
  "table_name": "cdk-project-table"
}

To get the these values: VERSION, DEPLOYMENT_NAME, PLATFORM_PREFIX, TABLE_PREFIX, TABLE_NAME, from the config file, call the getConfig().

1.7.0

4 months ago

1.5.5

1 year ago

1.5.4

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.6.0

1 year ago

1.5.1

1 year ago

1.5.10

1 year ago

1.5.9

1 year ago

1.5.8

1 year ago

1.5.7

1 year ago

1.5.6

1 year ago

1.4.2

1 year ago

1.5.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago