turnerlabs / cstore-lambda-layer

cStore lambda layer terraform scripts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cStore Lambda Layer

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.

NodeJS

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

1. Create cStore Lambda Layer

$ cd nodejs/resources
$ terraform init
$ terraform apply

3. Create Example Lambda

$ 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

2. Push Example Configuration to SSM Parameter Store

$ cd nodejs/example/lambda
$ cstore push ../.env

4. Execute Example Lambda

$ export AWS_DEFAULT_REGION=us-east-1
$ aws lambda invoke --function-name cstore_lambda_example response.json

About

cStore lambda layer terraform scripts.


Languages

Language:HCL 86.8%Language:JavaScript 13.2%