LambdaUtilStack
Stack props can be found in LambdaProps
This stack provides an L3
equivalent construct that creates a Lambda with:
- Versioning and Aliasing, each Cloudformation deployment releases a new version and updates alias
- Extra actions that allow configuring external interactions with the lambda by providing the
scope
,alias
,role
and other - SQS DLQ
- Alarms sent to SNS topic
- Layers support via arn, zip, parameter store arn
- VPC support
- Role generation per environment
Example
YourStack.ts
import { App } from 'aws-cdk-lib';
import { LambdaUtilStack } from 'aws-cdk-lib-util';
const app = new App();
export const lambdaCvExport: LambdaProps = {
alarmTopicParam: `/${PROJECT_NAME_MAIN.toLowerCase()}${PARAM_SNS_ALARMS_ARN}`,
artifactPath: artifactPathCvExport,
environmentGeneration: () => ({
APP_NAME: nameCapitalizedCvExport,
CV_URL: `cv.${process.env.CDK_DOMAIN_NAME}`,
}),
extraActions: ({ lambdaAlias }) =>
lambdaAlias.grantInvoke(
new ServicePrincipal('cloudformation.amazonaws.com')
),
isInVpc: false,
isProvisioned: false,
managedPolicies: ['service-role/AWSLambdaBasicExecutionRole'],
memorySize: 1024,
layers: [{ paramName: PARAM_LAMBDA_CV_EXPORT_LAYER_ARN }],
name: `${PROJECT_NAME}-${nameCapitalizedCvExport}`,
paramName: PARAM_LAMBDA_CV_EXPORT_ALIAS_ARN,
paramNameRole: PARAM_LAMBDA_CV_EXPORT_ROLE_ARN,
runtime: Runtime.NODEJS_14_X,
policies: (env, stackEnv) =>
getApiIAMPolicies(lambdaNameCvExport)(env, PROJECT_NAME, stackEnv),
};
const lambda = new LambdaUtilStack(
app,
`${PROJECT_NAME}-Lambda-API-${process.ENV}`,
lambdaCvExport
);