# lambda-elasticsearch-kibana

> CDK Constructs for AWS Lambda to AWS Elasticsearch with Kibana integration

Latest version **1.125.0** (published 2021-10-08) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install lambda-elasticsearch-kibana
pnpm add lambda-elasticsearch-kibana
yarn add lambda-elasticsearch-kibana
bun add lambda-elasticsearch-kibana
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.125.0 |
| Published | 2021-10-08 |
| First published | 2021-10-08 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 237.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Thanh Nguyen |
| Maintainers | nnthanh101 |
| Keywords | aws, cdk, CDK Constructs, Amazon Elasticsearch Service, AWS Lambda |

## Links

- npm: https://www.npmjs.com/package/lambda-elasticsearch-kibana
- Repository: https://github.com/Job4U101/CDK-Patterns
- Homepage: https://github.com/Job4U101/CDK-Patterns#readme
- Issues: https://github.com/Job4U101/CDK-Patterns/issues
- npm.io page: https://npm.io/package/lambda-elasticsearch-kibana

## Dependencies (8)

- [constructs](https://npm.io/package/constructs.md) ^3.3.161
- [@aws-cdk/core](https://npm.io/package/@aws-cdk/core.md) ^1.125.0
- [@aws-cdk/aws-iam](https://npm.io/package/@aws-cdk/aws-iam.md) ^1.125.0
- [@aws-cdk/aws-lambda](https://npm.io/package/@aws-cdk/aws-lambda.md) ^1.125.0
- [@aws-cdk/aws-cognito](https://npm.io/package/@aws-cdk/aws-cognito.md) ^1.125.0
- [@aws-cdk/aws-cloudwatch](https://npm.io/package/@aws-cdk/aws-cloudwatch.md) ^1.125.0
- [@aws-cdk/aws-elasticsearch](https://npm.io/package/@aws-cdk/aws-elasticsearch.md) ^1.125.0
- [@aws-solutions-constructs/core](https://npm.io/package/@aws-solutions-constructs/core.md) ^1.125.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.125.0 (latest) — 2021-10-08

## README

# Lambda >> ElasticSearch >> Kibana

![Stability: Experimental](https://img.shields.io/badge/stability-Experimental-important.svg?style=for-the-badge)

This AWS Solutions Construct implements the AWS Lambda function and Amazon ElasticSearch Service with the least privileged permissions.

## Architecture
![Architecture Diagram](architecture.png)


> Here is a minimal deployable pattern definition in Typescript:

``` typescript
import { LambdaToElasticSearchAndKibana } from 'lambda-elasticsearch-kibana';
import { Aws } from "@aws-cdk/core";

const lambdaProps: lambda.FunctionProps = {
    code: lambda.Code.fromAsset(`${__dirname}/lambda`),
    runtime: lambda.Runtime.NODEJS_14_X,
    handler: 'index.handler'
};

new LambdaToElasticSearchAndKibana(this, 'test-lambda-elasticsearch-kibana', {
    lambdaFunctionProps: lambdaProps,
    domainName: 'test-domain',
    // TODO: Ensure the Cognito domain name is globally unique
    cognitoDomainName: 'globallyuniquedomain' + Aws.ACCOUNT_ID;
});

```

## Initializer

``` text
new LambdaToElasticSearchAndKibana(scope: Construct, id: string, props: LambdaToElasticSearchAndKibanaProps);
```

_Parameters_

* scope [`Construct`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.Construct.html)
* id `string`
* props [`LambdaToElasticSearchAndKibanaProps`](#pattern-construct-props)

## Pattern Construct Props

| **Name**     | **Type**        | **Description** |
|:-------------|:----------------|-----------------|
|existingLambdaObj?|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Existing instance of Lambda Function object, providing both this and `lambdaFunctionProps` will cause an error.|
|lambdaFunctionProps?|[`lambda.FunctionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.FunctionProps.html)|User provided props to override the default props for the Lambda function.|
|esDomainProps?|[`elasticsearch.CfnDomainProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-elasticsearch.CfnDomainProps.html)|Optional user provided props to override the default props for the ElasticSearch Service|
|domainName|`string`|Domain name for the Cognito and the ElasticSearch Service|
|cognitoDomainName?|`string`|Optional Cognito Domain Name, if provided it will be used for Cognito Domain, and domainName will be used for the ElasticSearch Domain|
|createCloudWatchAlarms|`boolean`|Whether to create recommended CloudWatch alarms|
|domainEndpointEnvironmentVariableName?|`string`|Optional Name for the ElasticSearch domain endpoint environment variable set for the Lambda function.|

## Pattern Properties

| **Name**     | **Type**        | **Description** |
|:-------------|:----------------|-----------------|
|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct|
|userPool|[`cognito.UserPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPool.html)|Returns an instance of cognito.UserPool created by the construct|
|userPoolClient|[`cognito.UserPoolClient`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.UserPoolClient.html)|Returns an instance of cognito.UserPoolClient created by the construct|
|identityPool|[`cognito.CfnIdentityPool`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cognito.CfnIdentityPool.html)|Returns an instance of cognito.CfnIdentityPool created by the construct|
|elasticsearchDomain|[`elasticsearch.CfnDomain`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-elasticsearch.CfnDomain.html)|Returns an instance of elasticsearch.CfnDomain created by the construct|
|elasticsearchDomain|[`iam.Role`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iam.Role.html)|Returns an instance of iam.Role created by the construct for elasticsearch.CfnDomain|
|cloudwatchAlarms?|[`cloudwatch.Alarm[]`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-cloudwatch.Alarm.html)|Returns a list of cloudwatch.Alarm created by the construct|

## Lambda Function

This pattern requires a lambda function that can post data into the ElasticSearch. A sample function is provided [here](https://github.com/Job4U101/CDK-Patterns/blob/master/cdk/constructs/lambda-elasticsearch-kibana/test/lambda/index.js).

## Default settings

Out of the box implementation of the Construct without any override will set the following defaults:

### AWS Lambda Function
* Configure limited privilege access IAM role for Lambda function
* Enable reusing connections with Keep-Alive for NodeJs Lambda function
* Enable X-Ray Tracing
* Set Environment Variables
  * (default) DOMAIN_ENDPOINT
  * AWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 12.x and higher functions)

### Amazon Cognito
* Set password policy for User Pools
* Enforce the advanced security mode for User Pools

### Amazon ElasticSearch Service
* Deploy best practices CloudWatch Alarms for the ElasticSearch Domain
* Secure the Kibana dashboard access with Cognito User Pools
* Enable server-side encryption for ElasticSearch Domain using AWS managed KMS Key
* Enable node-to-node encryption for ElasticSearch Domain
* Configure the cluster for the Amazon ES domain

---
_Source: https://npm.io/package/lambda-elasticsearch-kibana · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
