Skip to content

Commit

Permalink
feat: add NodejsFunction construct and create common alarm infra (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
afenton90 committed Sep 28, 2023
1 parent ec24592 commit 8db3112
Show file tree
Hide file tree
Showing 9 changed files with 1,802 additions and 127 deletions.
58 changes: 51 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# AWS Constructs

This repo contains thin wrappers for CDK constructs to ensure a consistent standard is applied to generated cloud resources and to avoid repetitive boilerplate code.

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

## Preamble

There are a few conventions when using this library to be aware of.

1. Constructs expect the CDK [context values](https://docs.aws.amazon.com/cdk/v2/guide/cli.html#w53aac33b7c33c11) `ENVIRONMENT` and `CUSTOMER` to be declared via the CLI:
2. `ENVIRONMENT` - eg: `dev`, `stage`, `prod` etc but you can use whatever you want
3. `CUSTOMER` - a string representing the end client of your software. This library is built with a SaaS mindset, where each customer can have their own configuration. If this doesn't apply to you we recommend simply using your own business name.
1. Constructs expect the CDK [context values](https://docs.aws.amazon.com/cdk/v2/guide/cli.html#w53aac33b7c33c11) `ENVIRONMENT` and `CUSTOMER` to be declared via the CLI: 2. `ENVIRONMENT` - eg: `dev`, `stage`, `prod` etc but you can use whatever you want 3. `CUSTOMER` - a string representing the end client of your software. This library is built with a SaaS mindset, where each customer can have their own configuration. If this doesn't apply to you we recommend simply using your own business name.
2. Your `cdk.context.json` [file](https://docs.aws.amazon.com/cdk/v2/guide/context.html) should adopt a structure of:

```json
{
"cuckoo": { // <--- customer(s)
"prod": { // <--- environment(s)
"logLevel": "debug" // <--- option(s)
"cuckoo": {
// <--- customer(s)
"prod": {
// <--- environment(s)
"logLevel": "debug" // <--- option(s)
}
}
}
Expand Down Expand Up @@ -76,7 +80,12 @@ import * as lambda from "aws-cdk-lib/aws-lambda";
import * as AWSConstructs from "@cuckoointernet/aws-constructs";

class ExampleFunction extends AWSConstructs.lambda.Function {
constructor(scope: Construct, id: string, props: lambda.FunctionProps, customProps?: CustomLambdaProps) {
constructor(
scope: Construct,
id: string,
props: lambda.FunctionProps,
customProps?: CustomLambdaProps
) {
super(
scope,
ExampleFunction.name,
Expand All @@ -95,6 +104,41 @@ class ExampleFunction extends AWSConstructs.lambda.Function {
}
```

## `lambda.NodejsFunction`

As well as the [usual defaults](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs.NodejsFunction.html#construct-props), this construct will additionally configure the same properties as [`lambda.Function`](#lambda.function). This construct is specifically aimed at taking advantage of the same great defaults, but giving the option to use [`esbuild`](https://esbuild.github.io) to build Lambda source code.

### Usage

```typescript
import * as lambdaNode from "aws-cdk-lib/aws-lambda-nodejs";
import * as CuckooConstructs from "@cuckoointernet/cuckoo-constructs";

class ExampleFunction extends CuckooConstructs.lambda.NodejsFunction {
constructor(
scope: Construct,
id: string,
props: lambdaNode.NodejsFunctionProps,
customProps?: CustomLambdaProps
) {
super(
scope,
ExampleFunction.name,
{
entry: "src/lambda/node-mock-handler.ts",
handler: "handleTheStuff",

// To override the default behaviour of this construct you can supply your own props here...
// See: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html#construct-props
},
{
// Custom Cuckoo Construct options
}
);
}
}
```

## `sqs.Queue`

As well as the [usual defaults](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_sqs.Queue.html#construct-props), this construct will additionally configure the following for you:
Expand Down

0 comments on commit 8db3112

Please sign in to comment.