Skip to content

Latest commit

 

History

History
752 lines (496 loc) · 22.5 KB

API.md

File metadata and controls

752 lines (496 loc) · 22.5 KB

cdk-redisdb

An AWS CDK construct which spins up an Elasticache Replication Group, or a MemoryDB Cluster.

Usage (TypeScript/JavaScript)

Install via npm:

$ npm i cdk-redisdb

Add an Elasticache Replication Group to your CDK stack:

import { RedisDB } from 'cdk-redisdb'

new RedisDB(this, 'redisdb-repl-group', {
  nodes: 1,
  nodeType: 'cache.m6g.large',
  engineVersion: '6.2',
})

Add a MemoryDB Cluster to your CDK stack:

import { MemoryDB } from 'cdk-redisdb'

new MemoryDB(this, 'memorydb-repl-group', {
  nodes: 1,
  nodeType: 'db.t4g.small',
  engineVersion: '6.2',
})

Specify a VPC rather than having a VPC auto-created for you:

import { MemoryDB } from 'cdk-redisdb'

let vpc = new ec2.Vpc(this, 'Vpc', {
  subnetConfiguration: [
    {
      cidrMask: 24,
      name: 'public1',
      subnetType: ec2.SubnetType.PUBLIC,
    },
    {
      cidrMask: 24,
      name: 'isolated1',
      subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
    },
  ],
})

new RedisDB(this, 'redis-use-existing-vpc', {
  existingVpc: vpc,
})

Add 2 replicas per node, and add shards to cluster when memory exceeds 60%.

import { RedisDB } from 'cdk-redisdb'

new RedisDB(this, 'redisdb-repl-group', {
  nodes: 1,
  replicas: 2, // 2 replicas per node
  nodeType: 'cache.m6g.large',
  memoryAutoscalingTarget: 60,
  // nodesCpuAutoscalingTarget
})
import { RedisDB } from 'cdk-redisdb'

let vpc = new ec2.Vpc(this, 'Vpc', {
  subnetConfiguration: [
    {
      cidrMask: 24,
      name: 'public1',
      subnetType: ec2.SubnetType.PUBLIC,
    },
    {
      cidrMask: 24,
      name: 'isolated1',
      subnetType: ec2.SubnetType.PRIVATE,
    },
  ],
})

const ecSecurityGroup = new ec2.SecurityGroup(this, 'elasticache-sg', {
  vpc: vpc,
  description: 'SecurityGroup associated with the ElastiCache Redis Cluster',
  allowAllOutbound: false,
});

new RedisDB(this, 'redisdb-repl-group', {
  nodes: 1,
  nodeType: 'cache.m6g.large',
  nodesCpuAutoscalingTarget: 50,
  existingVpc: vpc,
  existingSecurityGroup: ecSecurityGroup,
})

Features in progress:

  • MemoryDB ACLs (commented out to avoid default bad practices, read comments to understand the CloudFormation)

Features to come:

  • Replication Groups with cluster mode disabled (for those using multiple databases)
  • Improved API - sane choice of props

API Reference

Constructs

MemoryDB

Initializers

import { MemoryDB } from 'cdk-redisdb'

new MemoryDB(scope: Construct, id: string, props?: RedisDBProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props RedisDBProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsOptional

Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { MemoryDB } from 'cdk-redisdb'

MemoryDB.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.
cluster aws-cdk-lib.aws_memorydb.CfnCluster No description.
vpc aws-cdk-lib.aws_ec2.IVpc No description.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


clusterRequired
public readonly cluster: CfnCluster;
  • Type: aws-cdk-lib.aws_memorydb.CfnCluster

vpcRequired
public readonly vpc: IVpc;
  • Type: aws-cdk-lib.aws_ec2.IVpc

RedisDB

Initializers

import { RedisDB } from 'cdk-redisdb'

new RedisDB(scope: Construct, id: string, props?: RedisDBProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props RedisDBProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsOptional

Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { RedisDB } from 'cdk-redisdb'

RedisDB.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.
replicationGroup aws-cdk-lib.aws_elasticache.CfnReplicationGroup No description.
vpc aws-cdk-lib.aws_ec2.IVpc No description.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


replicationGroupRequired
public readonly replicationGroup: CfnReplicationGroup;
  • Type: aws-cdk-lib.aws_elasticache.CfnReplicationGroup

vpcRequired
public readonly vpc: IVpc;
  • Type: aws-cdk-lib.aws_ec2.IVpc

Structs

RedisDBProps

Initializer

import { RedisDBProps } from 'cdk-redisdb'

const redisDBProps: RedisDBProps = { ... }

Properties

Name Type Description
analyticsReporting boolean Include runtime versioning information in this Stack.
crossRegionReferences boolean Enable this flag to allow native cross region stack references.
description string A description of the stack.
env aws-cdk-lib.Environment The AWS environment (account/region) where this stack will be deployed.
permissionsBoundary aws-cdk-lib.PermissionsBoundary Options for applying a permissions boundary to all IAM Roles and Users created within this Stage.
stackName string Name to deploy the stack with.
synthesizer aws-cdk-lib.IStackSynthesizer Synthesis method to use while deploying this stack.
tags {[ key: string ]: string} Stack tags that will be applied to all the taggable resources and the stack itself.
terminationProtection boolean Whether to enable termination protection for this stack.
atRestEncryptionEnabled boolean | aws-cdk-lib.IResolvable No description.
authToken string No description.
engineVersion string No description.
existingSecurityGroup aws-cdk-lib.aws_ec2.ISecurityGroup No description.
existingSubnetGroupName string No description.
existingVpc aws-cdk-lib.aws_ec2.IVpc No description.
memoryAutoscalingTarget number No description.
nodes number No description.
nodesCpuAutoscalingTarget number No description.
nodeType string No description.
parameterGroupName string No description.
replicas number No description.
replicasCpuAutoscalingTarget number No description.
subnetGroupName string No description.
transitEncryptionEnabled boolean | aws-cdk-lib.IResolvable No description.

analyticsReportingOptional
public readonly analyticsReporting: boolean;
  • Type: boolean
  • Default: analyticsReporting setting of containing App, or value of 'aws:cdk:version-reporting' context key

Include runtime versioning information in this Stack.


crossRegionReferencesOptional
public readonly crossRegionReferences: boolean;
  • Type: boolean
  • Default: false

Enable this flag to allow native cross region stack references.

Enabling this will create a CloudFormation custom resource in both the producing stack and consuming stack in order to perform the export/import

This feature is currently experimental


descriptionOptional
public readonly description: string;
  • Type: string
  • Default: No description.

A description of the stack.


envOptional
public readonly env: Environment;
  • Type: aws-cdk-lib.Environment
  • Default: The environment of the containing Stage if available, otherwise create the stack will be environment-agnostic.

The AWS environment (account/region) where this stack will be deployed.

Set the region/account fields of env to either a concrete value to select the indicated environment (recommended for production stacks), or to the values of environment variables CDK_DEFAULT_REGION/CDK_DEFAULT_ACCOUNT to let the target environment depend on the AWS credentials/configuration that the CDK CLI is executed under (recommended for development stacks).

If the Stack is instantiated inside a Stage, any undefined region/account fields from env will default to the same field on the encompassing Stage, if configured there.

If either region or account are not set nor inherited from Stage, the Stack will be considered "environment-agnostic"". Environment-agnostic stacks can be deployed to any environment but may not be able to take advantage of all features of the CDK. For example, they will not be able to use environmental context lookups such as ec2.Vpc.fromLookup and will not automatically translate Service Principals to the right format based on the environment's AWS partition, and other such enhancements.


Example

// Use a concrete account and region to deploy this stack to:
// `.account` and `.region` will simply return these values.
new Stack(app, 'Stack1', {
  env: {
    account: '123456789012',
    region: 'us-east-1'
  },
});

// Use the CLI's current credentials to determine the target environment:
// `.account` and `.region` will reflect the account+region the CLI
// is configured to use (based on the user CLI credentials)
new Stack(app, 'Stack2', {
  env: {
    account: process.env.CDK_DEFAULT_ACCOUNT,
    region: process.env.CDK_DEFAULT_REGION
  },
});

// Define multiple stacks stage associated with an environment
const myStage = new Stage(app, 'MyStage', {
  env: {
    account: '123456789012',
    region: 'us-east-1'
  }
});

// both of these stacks will use the stage's account/region:
// `.account` and `.region` will resolve to the concrete values as above
new MyStack(myStage, 'Stack1');
new YourStack(myStage, 'Stack2');

// Define an environment-agnostic stack:
// `.account` and `.region` will resolve to `{ "Ref": "AWS::AccountId" }` and `{ "Ref": "AWS::Region" }` respectively.
// which will only resolve to actual values by CloudFormation during deployment.
new MyStack(app, 'Stack1');
permissionsBoundaryOptional
public readonly permissionsBoundary: PermissionsBoundary;
  • Type: aws-cdk-lib.PermissionsBoundary
  • Default: no permissions boundary is applied

Options for applying a permissions boundary to all IAM Roles and Users created within this Stage.


stackNameOptional
public readonly stackName: string;
  • Type: string
  • Default: Derived from construct path.

Name to deploy the stack with.


synthesizerOptional
public readonly synthesizer: IStackSynthesizer;
  • Type: aws-cdk-lib.IStackSynthesizer
  • Default: The synthesizer specified on App, or DefaultStackSynthesizer otherwise.

Synthesis method to use while deploying this stack.

The Stack Synthesizer controls aspects of synthesis and deployment, like how assets are referenced and what IAM roles to use. For more information, see the README of the main CDK package.

If not specified, the defaultStackSynthesizer from App will be used. If that is not specified, DefaultStackSynthesizer is used if @aws-cdk/core:newStyleStackSynthesis is set to true or the CDK major version is v2. In CDK v1 LegacyStackSynthesizer is the default if no other synthesizer is specified.


tagsOptional
public readonly tags: {[ key: string ]: string};
  • Type: {[ key: string ]: string}
  • Default: {}

Stack tags that will be applied to all the taggable resources and the stack itself.


terminationProtectionOptional
public readonly terminationProtection: boolean;
  • Type: boolean
  • Default: false

Whether to enable termination protection for this stack.


atRestEncryptionEnabledOptional
public readonly atRestEncryptionEnabled: boolean | IResolvable;
  • Type: boolean | aws-cdk-lib.IResolvable

authTokenOptional
public readonly authToken: string;
  • Type: string

engineVersionOptional
public readonly engineVersion: string;
  • Type: string

existingSecurityGroupOptional
public readonly existingSecurityGroup: ISecurityGroup;
  • Type: aws-cdk-lib.aws_ec2.ISecurityGroup

existingSubnetGroupNameOptional
public readonly existingSubnetGroupName: string;
  • Type: string

existingVpcOptional
public readonly existingVpc: IVpc;
  • Type: aws-cdk-lib.aws_ec2.IVpc

memoryAutoscalingTargetOptional
public readonly memoryAutoscalingTarget: number;
  • Type: number

nodesOptional
public readonly nodes: number;
  • Type: number

nodesCpuAutoscalingTargetOptional
public readonly nodesCpuAutoscalingTarget: number;
  • Type: number

nodeTypeOptional
public readonly nodeType: string;
  • Type: string

parameterGroupNameOptional
public readonly parameterGroupName: string;
  • Type: string

replicasOptional
public readonly replicas: number;
  • Type: number

replicasCpuAutoscalingTargetOptional
public readonly replicasCpuAutoscalingTarget: number;
  • Type: number

subnetGroupNameOptional
public readonly subnetGroupName: string;
  • Type: string

transitEncryptionEnabledOptional
public readonly transitEncryptionEnabled: boolean | IResolvable;
  • Type: boolean | aws-cdk-lib.IResolvable