0.0.2 • Published 7 days ago

@studyportals/cdk-lambda-config v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 days ago

CDK Construct for adding config.json file to a Lambda Function

When using Lambda@Edge, a function cannot use environment variables. This CDK Construct uses a Custom Resource to inject a config.json file with user provided values into an existing function, and publishes a new version that is ready to be used as part of a CloudFront Distribution.

Inspired by similar mechanism in https://github.com/aws-samples/cloudfront-authorization-at-edge/

Usage

npm install @studyportals/cdk-lambda-config

Using the construct:

const originalFunction = lambda.Function.fromFunctionArn(...)
const updatedFunction = new LambdaConfig(this, "UpdatedFunction", {
  function: originalFunction,
  config: {
    Key1: "Some value",
    Nested: {
      Key2: "Other value",
    },
  },
  nonce: "1", // See TSDoc.
}
// Can now retrieve the new version:
updatedFunction.version

Read from within the handler:

const fs = require("fs")
const path = require("path")
const config = JSON.parse(
  fs.readFileSync(path.join(__dirname, "config.json"), "utf-8"),
)

If function update is meant to run concurrently targeting the same function, you can pass locksTable property in the config object, pointing to a table that's been created using LockableTable.create(this,"UpdateCodeLocks") in the project that uses @studyportals/cdk-lambda-config This will ensure that multiple stacks won't get stuck while trying to update the same function

0.0.3

7 days ago

0.0.2

2 months ago

0.0.1

1 year ago

0.0.1-dev.15

1 year ago

0.0.1-dev.14

1 year ago

0.0.1-dev.13

1 year ago

0.0.1-dev.12

1 year ago

0.0.1-dev.10

1 year ago

0.0.1-dev.9

1 year ago

0.0.1-dev.8

1 year ago

0.0.1-dev.7

1 year ago

0.0.1-dev.6

1 year ago

0.0.1-dev.5

1 year ago

0.0.1-dev.4

1 year ago

0.0.1-dev.3

1 year ago

0.0.1-dev.2

1 year ago

0.0.1-dev.1

1 year ago

0.0.1-dev.0

1 year ago