2.3.0 • Published 6 months ago

aws-typescript-toolkit v2.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 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

// cloud-development
import { Config, Construct, Types, Utils } from 'aws-typescript-toolkit/cloud-development';

const { createConstructs, setResources, ConstructMiddleware } = Construct;
const { createFileNameHandler, constructName, generateName, getConstructs } = Utils;
const { StackProps, ConstructTypes, IConstruct, INewConstruct } = Types;
const { getConfig } = Config;
const { VERSION, DEPLOYMENT_NAME, PLATFORM_PREFIX, TABLE_NAME } = getConfig();


// software-development
import { BaseHandler, Repository, Service, Services, Exceptions } from 'aws-typescript-toolkit/software-development';

const { Bucket, DeepLink, Dynamodb, Event, Logger, SSM } = Services;
const { BaseError, BackendError, DatabaseError } = Exceptions;

Construct

Utilities to simplify setting up of constructs.

  • createConstructs

Usage is similar to createSlice from Redux Toolkit.

// cdk/constructs/lambda/EntityName.ts

import { Construct, Config } from 'aws-typescript-toolkit/cloud-development';
import { Services } from 'aws-typescript-toolkit/software-development';

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().

2.3.0

6 months ago

2.2.0

7 months ago

2.0.0

8 months ago

2.1.0

8 months ago

1.10.0

8 months ago

1.9.7

8 months ago

1.9.6

8 months ago

1.9.1

9 months ago

1.9.0

9 months ago

1.9.5

9 months ago

1.9.4

9 months ago

1.9.3

9 months ago

1.9.2

9 months ago

1.8.10

10 months ago

1.8.11

10 months ago

1.8.12

10 months ago

1.8.13

10 months ago

1.8.2

10 months ago

1.8.1

10 months ago

1.8.0

10 months ago

1.8.9

10 months ago

1.8.8

10 months ago

1.8.7

10 months ago

1.8.6

10 months ago

1.8.5

10 months ago

1.8.4

10 months ago

1.8.3

10 months ago

1.7.1

1 year ago

1.7.0

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.6.0

2 years ago

1.5.1

2 years ago

1.5.10

2 years ago

1.5.9

2 years ago

1.5.8

2 years ago

1.5.7

2 years ago

1.5.6

2 years ago

1.4.2

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago