Skip to content

theonestack/hl-component-elasticache-serverless

Repository files navigation

elasticache-serverless CfHighlander component

Description

This component provisions AWS ElastiCache Serverless caches with support for Redis, Memcached, and Valkey engines. ElastiCache Serverless provides a serverless option for caching that automatically scales based on demand, eliminating the need to manage cache nodes or plan for capacity.

Requirements

  • VPC with subnets
  • Optional: KMS key for encryption at rest
  • Optional: Route53 hosted zone for DNS records

Parameters

Stack parameters that can be provided at runtime:

Name Use Default Global Type Allowed Values
EnvironmentName Tagging and naming dev true String
EnvironmentType Tagging development true String ['development','production']
VPCId ID of the VPC to launch cache in false AWS::EC2::VPC::Id
Subnets Subnet IDs for cache subnet group false CommaDelimitedList
DnsDomain Domain for Route53 record false String
KmsKeyId KMS key ID for encryption (when kms_encryption enabled in config) false String

Note: Cache engine and version are configured at compile-time via config.yaml, not as runtime parameters.

Configuration

Basic Configuration

The simplest configuration uses the default Redis engine:

# This uses all defaults - Redis 7 with encryption enabled

Engine Selection

Important: Engine and version are compile-time configuration. These values are set when the CloudFormation template is generated and cannot be changed at stack runtime. To change the engine or version, you must recompile the template.

Redis (Default)

engine: redis
major_engine_version: '7'

Memcached

engine: memcached
major_engine_version: '1.6'
hostname: memcached

Valkey

Valkey is an open-source Redis fork:

engine: valkey
major_engine_version: '7'
hostname: valkey

Capacity Configuration

ElastiCache Serverless automatically scales, but you can set minimum and maximum limits:

cache_usage_limits:
  ecpu_per_second:
    minimum: 1000    # Minimum ECPUs per second
    maximum: 5000    # Maximum ECPUs per second
  data_storage:
    minimum: 1       # Minimum storage in GB
    maximum: 5       # Maximum storage in GB
    unit: GB

If not specified, AWS uses service-defined defaults which automatically scale based on your workload.

Encryption Configuration

ElastiCache Serverless automatically enables encryption at rest and in transit. These cannot be disabled.

To use a custom KMS key for encryption at rest (instead of the AWS managed key):

kms_encryption: true  # This enables the KmsKeyId parameter

Then provide the KMS key ID as a stack parameter when creating the stack.

Snapshot Configuration

For Redis and Valkey engines, you can configure automated snapshots:

daily_snapshot_time: "03:00"       # Time for daily snapshots (UTC)
snapshot_retention_limit: 7        # Number of days to retain (0-35)

Note: Snapshots are not available for Memcached.

DNS Configuration

By default, a Route53 CNAME record is created:

hostname: cache
dns_format: ${EnvironmentName}.${DnsDomain}
create_route53_record: true

This creates a DNS record like: cache.dev.example.com

To disable DNS record creation:

create_route53_record: false

Security Groups

Configure ingress rules for cache access:

security_group_rules:
  - protocol: tcp
    from: 6379
    to: 6379
    ip_blocks:
      - stack  # Reference to another stack's security group

Or allow from specific CIDR:

security_group_rules:
  - protocol: tcp
    from: 6379
    to: 6379
    cidr: 10.0.0.0/8

Tagging

Add custom tags to all resources:

tags:
  CostCenter: Engineering
  Project: ${EnvironmentName}-cache

Outputs

Output Description Export Name
SecurityGroupId ID of the cache security group ${EnvironmentName}-${ComponentName}-SecurityGroup
CacheEndpoint DNS endpoint address of the cache ${EnvironmentName}-${ComponentName}-Endpoint
CachePort Port number of the cache ${EnvironmentName}-${ComponentName}-Port
CacheFullEndpoint Full endpoint with port (host:port) ${EnvironmentName}-${ComponentName}-FullEndpoint
CacheArn ARN of the serverless cache ${EnvironmentName}-${ComponentName}-ARN
CacheDnsName Route53 DNS name (if created) ${EnvironmentName}-${ComponentName}-DnsName

Examples

Redis with Snapshots

engine: redis
major_engine_version: '7'
hostname: redis-cache

daily_snapshot_time: "02:00"
snapshot_retention_limit: 14

cache_usage_limits:
  ecpu_per_second:
    minimum: 2000
    maximum: 10000

Memcached with Custom Capacity

engine: memcached
major_engine_version: '1.6'
hostname: memcached

cache_usage_limits:
  data_storage:
    minimum: 2
    maximum: 8
    unit: GB

Valkey with Custom DNS

engine: valkey
major_engine_version: '7'
hostname: valkey-cache
dns_format: ${EnvironmentName}.internal.${DnsDomain}

security_group_rules:
  - protocol: tcp
    from: 6379
    to: 6379
    ip_blocks:
      - app-stack
      - worker-stack

No DNS Record

engine: redis
major_engine_version: '7'
create_route53_record: false

Notes

  • ElastiCache Serverless automatically handles scaling, backups, and patching
  • No instance type selection is needed - capacity is automatically managed
  • Pricing is based on data storage and compute (ECPUs) used
  • Snapshot features are only available for Redis and Valkey engines
  • For production workloads, consider enabling KMS encryption and configuring appropriate capacity limits

Dependencies

  • lib-ec2@0.1.0 - For security group rule generation

License

Apache 2.0 - See LICENSE file for details

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages