https://github.com/capralifecycle/cdk-lambda-config
https://github.com/capralifecycle/cdk-lambda-config
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/capralifecycle/cdk-lambda-config
- Owner: capralifecycle
- License: apache-2.0
- Created: 2025-06-27T13:42:02.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2026-02-28T06:31:15.000Z (4 months ago)
- Last Synced: 2026-02-28T12:28:22.722Z (4 months ago)
- Language: TypeScript
- Size: 7.14 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```bash
npm install @liflig/cdk-lambda-config
```
Using the construct:
```ts
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:
```ts
const fs = require("fs")
const path = require("path")
const config = JSON.parse(
fs.readFileSync(path.join(__dirname, "config.json"), "utf-8"),
)
```