aws-lambda-configuration front page
Assumed you had already setup your AWS access key, secret key and region (either in environment variable, aws profile, or any serverless framework supported way). ref: serverless - Credentials
curl https://raw.githubusercontent.com/tonyliu7870/aws-lambda-configuration-core/master/lazy_setup.sh | bash
-
Download the source code
Click "Download ZIP" from github orgit clone [email protected]:tonyliu7870/aws-lambda-configuration-core.git
or fork your own version (if you would like to save with your own settings). -
Go to directory
cd aws-lambda-configuration/
-
Install dependency
yarn install
ornpm install
-
Transpile typescript code
yarn build
ornpm run build
-
READ Configuration Storage part below
-
Deploy to AWS
yarn deploy -- --stage dev --region us-east-1
ornpm run deploy -- --stage dev --region us-east-1
aws-lambda-configuration use a DynamoDB table to store the configuration. By default, it sets up a new table named lambda-configurations for you via CloudFormation. However, it also DELETE the table BY DEFAULT when you remove aws-lambda-configuration via CloudFormation.
If you DO NOT want to include the DynamoDB resources into CloudFormation (recommended):
- Disable the default table first: Open ./serverless.yml, comment out the whole resources part at the end by prepending a #.
- Go to your AWS DynamoDB Console. Create a new table with any Table Name and Table settings. The table MUST has a Primary key named with configName and in String type.
This is a generic lambda function to handle all CRUD of the configuration. If you use the libraries, you may skip this part.
Parameter | Required? | Description |
---|---|---|
tableName | required | The dynamoDB table name used to store all the configurations. (default to be "lambda-configurations" but strongly recommended to be set) |
documentName | required | The document name in the table to access the config. (default to be "settings" but strongly recommended to be set) |
type | required | What to do with the config. Accept: "GET", "PUT", "DELETE", "CHECK" |
key | optional | The path to sub-object of the config. undefined would refer to the whole document |
data | required | The config object to set. Only available on "PUT" |
noCache | optional | Will the core return a cached version if available. Only available on "GET" and "CHECK" |
{
tableName: string;
documentName: string;
type: string;
key?: string;
data?: any;
noCache?: boolean;
}
{
"tableName": "myConfigTable",
"documentName": "myConfig",
"type": "PUT",
"data": {
"hello": "world",
"something": {
"sub": "data"
},
"another": [1,2,3,4,5]
}
}
{
"tableName": "myConfigTable",
"documentName": "myConfig",
"type": "PUT",
"key": "something.sub",
"data": "data v2"
}
Note: You can not directly set a config via a virtual path, e.g. "key": "something.sub.some.path.that.do.not.exist"
. Instead, your possible options are:
- Get the whole config -> use lodash.set to update the config -> replace the whole config.
- Find the deepest existing path -> update by
"key": "something.sub.some", "data": {"path":{"that":{"do":{"not":{"exist": "hi"}}}}}
- Consider how to restructure your configuration, e.g. flatten the config.
{
"tableName": "myConfigTable",
"documentName": "myConfig",
"type": "GET",
"noCache": true
}
// typeof result === 'object'
// result === {"hello":"world","something":{"sub": "data v2"},"another":[1,2,3,4,5]}
{
"tableName": "myConfigTable",
"documentName": "myConfig",
"type": "GET",
"key": "something.sub"
"noCache": false // default is false, i.e. use cache if available
}
// typeof result === 'string'
// result === "data v2"
{
"tableName": "myConfigTable",
"documentName": "user.id.012345",
"type": "CHECK",
// "key": "abcdef"
}
// typeof result === 'boolean'
// result === false
// If you adopt aws-lambda-configuration as your account management framework, this can be a mean to check whether a user exist.
{
"tableName": "myConfigTable",
"documentName": "myConfig",
"type": "DELETE",
// "key": "another[2]"
}
node_modules/.bin/serverless remove