Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
henrist committed Jul 11, 2020
0 parents commit 1177e09
Show file tree
Hide file tree
Showing 22 changed files with 17,287 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/dist/
/lib/
25 changes: 25 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
"plugins": [
"deprecation"
],
"overrides": [
{
"files": ["*.ts"]
}
],
"parserOptions": {
"project": "./tsconfig.eslint.json",
"sourceType": "module"
},
"rules": {
"deprecation/deprecation": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": "error"
}
}
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# See https://help.github.com/en/github/administering-a-repository/customizing-how-changed-files-appear-on-github
**/__snapshots__/** linguist-generated=true
19 changes: 19 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build
on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12'
- run: npm ci
- run: npm run lint
- run: npm run test
- run: npm run semantic-release
if: github.ref == 'refs/heads/master'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vscode/
node_modules/
/dist/
/lib/
/*.tgz
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"trailingComma": "all",
"semi": false
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Henrik Steen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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 @henrist/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"),
)
```
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
}
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
testMatch: ["**/*.test.ts"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
}
Loading

0 comments on commit 1177e09

Please sign in to comment.