Terraform scripts used to create a lambda layer for cstore. Lambda functions can use the lambda layer to pull configuration into memory avoiding environment variables or configuration files.
Example Usage
const cstore = require('cstore');
exports.test = function (event, context) {
let config = cstore.pull({
tags: [process.env.ENV],
format: "json-object",
inject: false
})
Object.keys(config).forEach(function (key) {
console.log(key + "=" + config[key]);
});
}
Infrastructure
$ export AWS_REGION=us-east-1
$ export AWS_PROFILE=aws-profile
$ cd nodejs/resources
$ terraform init
$ terraform apply
$ cd nodejs/example
$ touch terraform.tfvars
Add the cstore lambda layer arn from the previous step's output to terraform.tfvars
.
cstore_lambda_layer_arn = "{ARN}"
$ terraform init
$ terraform apply
$ cd nodejs/example/lambda
$ cstore push ../.env
$ export AWS_DEFAULT_REGION=us-east-1
$ aws lambda invoke --function-name cstore_lambda_example response.json