@croudtech/sst-utils
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

@croudtech/sst-utils

Common SST configuration utilities for AWS applications.

Installation

npm install @croudtech/sst-utils

Namespaced imports

This package supports namespaced imports that mirror the directory structure of the package.

So, for example, this import from the package root...

import { stacks } from '@croudtech/sst-utils';
const { BaseConfig, ParameterMap } = stacks.modules.config;

...is equivalent to an import direct from module directly...

import { BaseConfig, ParameterMap } from '@croudtech/sst-utils/stacks/modules/config';

Usage

Config

Utils for working with the Parameter store and Secrets manager

Below is example of defining and using a config class to access parameters and secrets in your SST based functions

import { BaseConfig, ParameterMap } from '@croudtech/sst-utils/stacks/modules/config';

// extend the BaseConfig class with the specific access your SST app needs
export class CommonConfig extends BaseConfig {
  secrets = [
    "AUTH_CLIENT_ID",
    "AUTH_CLIENT_SECRET",
    "AUTH_TOKEN_ENDPOINT",
  ];
  configName: string = "common";
  data: ParameterMap = {
    CROUD_PLATFORM_API_URL: process.env.CROUD_PLATFORM_API_URL,
  }
}

// initialize and load the config class
const commonConfig = new CommonConfig(stack, environment)
const commonParameters = await commonConfig.load()

// Build a policy based on the config defined in the config class
const policyConstruct = new PolicyConstruct(stack, "PolicyConstruct", {
    parameters: [
        ...commonConfig.parameterNames,
    ]
})

// Use the parameters in your SST app
 const apiFunction = new Function(stack, 'ApiFunction', {
    handler: 'app/app.handler',
    runtime: 'python3.12',
    environment: {
      ...commonParameters,
    },
    initialPolicy: [
      policyConstruct.parameterPolicyStatement, 
      policyConstruct.secretPolicyStatement
    ],
  })

VPC

Utils for working with VPCs Below is example of defining a VPC stack in your SST app

import { StackContext, use } from "sst/constructs";
import { Vpc } from "@croudtech/sst-utils/stacks/modules/vpc";
import { Shared } from "./SharedStack";

export function VpcStack({ stack }: StackContext) {
  const { params } = use(Shared)
  const vpcId = params.AWS_VPC_ID as string;

  const vpcInstance = new Vpc(stack, vpcId);

  return {
    vpc: vpcInstance.vpc,
    lambdaSecurityGroups: [vpcInstance.createSecurityGroup()],
  };
}

CI

NPM publish

This repo will automatically publish to npm on create of a new release

Readme

Keywords

Package Sidebar

Install

npm i @croudtech/sst-utils

Weekly Downloads

0

Version

0.1.7

License

MIT

Unpacked Size

23.2 kB

Total Files

12

Last publish

Collaborators

  • paul-watkins-croud
  • croud_admin
  • brockreece