Common SST configuration utilities for AWS applications.
npm install @croudtech/sst-utils
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';
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
],
})
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()],
};
}
This repo will automatically publish to npm on create of a new release