|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Cryptocurrency News Articles
Deploy Amazon ElastiCache for Redis clusters using AWS CDK and TypeScript | AWS Database Blog
Apr 05, 2024 at 11:25 pm
The AWS Cloud Development Kit (AWS CDK) allows you to create AWS resources with a single line of code. For example, you can create a VPC in TypeScript with the following line:new EC2.Vpc(this, 'cache_vpc');However, several AWS resources require several lines of code because you often need to create supporting resources. For example, you need to create a CfnSubnetGroup and a SecurityGroup before creating an Amazon ElastiCache for Redis CfnReplicationGroup. This abstract demonstrates the steps to deploy an Amazon ElastiCache cluster using AWS CDK and TypeScript. We also show you how to deploy resources using Amazon ElastiCache for Redis Serverless.

Creating AWS Resources with AWS Cloud Development Kit (AWS CDK) for ElastiCache
Introduction
AWS Cloud Development Kit (AWS CDK) enables developers to define and provision AWS resources using familiar programming languages such as TypeScript. This article guides readers through the process of deploying an Amazon ElastiCache cluster and ElastiCache Serverless resources using AWS CDK and TypeScript.
Prerequisites
- AWS account
- AWS Command Line Interface (AWS CLI)
- AWS CDK
- Node.js 16.14.0 or later
Creating Prerequisite Resources
- Install AWS CDK:
npm install -g aws-cdk
cdk --version- Create AWS CDK Directory Structure:
mkdir work & cd work
cdk init --language typescript- Install NPM Packages:
npm install- Create VPC:
In the lib/work-stack.ts file, create a VPC:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as EC2 from 'aws-cdk-lib/aws-ec2';
export class WorkStack extends cdk.Stack {
private vpc: EC2.Vpc;
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
this.vpc = new EC2.Vpc(this, 'cache_vpc');
}
}- Bootstrap AWS Environment:
cdk bootstrap- Synthesize CloudFormation Template:
cdk synth- Deploy VPC:
cdk deploy --require-approval neverCreate Subnet Group
- Update
lib/work-stack.tsto create a subnet group for ElastiCache:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as EC2 from 'aws-cdk-lib/aws-ec2';
import { aws_elasticache as ElastiCache } from 'aws-cdk-lib';
export class WorkStack extends cdk.Stack {
private vpc: EC2.Vpc;
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
const groupName = "ElastiCacheSubnetGroup";
super(scope, id, props);
this.vpc = new EC2.Vpc(this, 'cache_vpc');
const subnetIds = [];
for (const subnet of this.vpc.privateSubnets) {
console.log("createElastiCache subnet ID: ", subnet.subnetId);
subnetIds.push(subnet.subnetId);
}
const subnetGroup = new ElastiCache.CfnSubnetGroup(this, "ElastiCacheSubnetGroup", {
cacheSubnetGroupName: groupName,
subnetIds: subnetIds,
description: "ElastiCache Subnet Group",
});
}
}- Synthesize and deploy the stack:
cdk synth; cdk deploy --require-approval neverCreating an ElastiCache for Redis Replication Group
- Create Security Group:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as EC2 from 'aws-cdk-lib/aws-ec2';
import { aws_elasticache as ElastiCache } from 'aws-cdk-lib';
import { SecurityGroup, Peer, Port } from 'aws-cdk-lib/aws-ec2';
export class WorkStack extends cdk.Stack {
private vpc: EC2.Vpc;
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
const groupName = "ElastiCacheSubnetGroup";
super(scope, id, props);
this.vpc = new EC2.Vpc(this, 'cache_vpc');
const subnetIds = [];
for (const subnet of this.vpc.privateSubnets) {
console.log("createElastiCache subnet ID: ", subnet.subnetId);
subnetIds.push(subnet.subnetId);
}
const subnetGroup = new ElastiCache.CfnSubnetGroup(this, "ElastiCacheSubnetGroup", {
cacheSubnetGroupName: groupName,
subnetIds: subnetIds,
description: "ElastiCache Subnet Group",
});
const securityGroup = new SecurityGroup(this, "ElastiCacheSecurityGroup", {
vpc: this.vpc,
allowAllOutbound: true,
description: "ElastiCache Security Group",
securityGroupName: "ElastiCacheSecurityGroup",
});
securityGroup.addIngressRule(Peer.anyIpv4(), Port.tcp(6379), "Redis port");
}
}- Create Replication Group:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as EC2 from 'aws-cdk-lib/aws-ec2';
import { aws_elasticache as ElastiCache } from 'aws-cdk-lib';
import { SecurityGroup, Peer, Port } from 'aws-cdk-lib/aws-ec2';
export class WorkStack extends cdk.Stack {
private vpc: EC2.Vpc;
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
const groupName = "ElastiCacheSubnetGroup";
super(scope, id, props);
this.vpc = new EC2.Vpc(this, 'cache_vpc');
const subnetIds = [];
for (const subnet of this.vpc.privateSubnets) {
console.log("createElastiCache subnet ID: ", subnet.subnetId);
subnetIds.push(subnet.subnetId);
}
const subnetGroup = new ElastiCache.CfnSubnetGroup(this, "ElastiCacheSubnetGroup", {
cacheSubnetGroupName: groupName,
subnetIds: subnetIds,
description: "ElastiCache Subnet Group",
});
const securityGroup = new SecurityGroup(this, "ElastiCacheSecurityGroup", {
vpc: this.vpc,
allowAllOutbound: true,
description: "ElastiCache Security Group",
securityGroupName: "ElastiCacheSecurityGroup",
});
securityGroup.addIngressRule(Peer.anyIpv4(), Port.tcp(6379), "Redis port");
const cache = new ElastiCache.CfnReplicationGroup(this, "ReplicationGroup", {
replicationGroupDescription: "Elastic Cache Replication Group",
numCacheClusters: 1,
automaticFailoverEnabled: false,
engine: 'redis',
cacheNodeType: 'cache.m7g.large',
cacheSubnetGroupName: subnetGroup.ref,
securityGroupIds: [securityGroup.securityGroupId],
});
// Establish dependency between cache and subnetGroup
cache.addDependency(subnetGroup);
}
}- Synthesize and deploy the stack:
cdk synth; cdk deploy --require-approval neverDeploying ElastiCache for Redis Serverless Resources
- Create Security Group:
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as EC2 from 'aws-cdk-lib/aws-ec2';
import { aws_elasticache as ElastiCache } from 'aws-cdk-lib';
import { SecurityGroup, Peer, Port } from 'aws-cdk-lib/aws-ec2';
export class WorkStack extends cdk.Stack {
private vpc: EC2.Vpc;
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
const groupName = "ElastiCacheSubnetGroup";
super(scope, id, props);
this.vpc = new EC2.Vpc(this, 'cache_vpc');
const subnetIds = [];
for (const subnet of this.vpc.privateSubnets) {
console.log("createElastiCache subnet ID: ", subnet.subnetId);
subnetIds.push(subnet.subnetId);
}
const subnetGroup = new ElastiCache.CfnSubnetGroup(this, "ElastiCacheSubnetGroup", {
cacheSubnetGroupName: groupName,
subnetIds: subnetIds,
description: "ElastiCache Subnet Group",
});
const securityGroup = new SecurityGroup(this, "ElastiCacheSecurityGroup", {
vpc: this.vpc,
allowAllOutbound: true,
description: "ElastiCache Security Group",
securityGroupName: "ElastiCacheSecurityGroup",
});
Disclaimer:info@kdj.com
The information provided is not trading advice. kdj.com does not assume any responsibility for any investments made based on the information provided in this article. Cryptocurrencies are highly volatile and it is highly recommended that you invest with caution after thorough research!
If you believe that the content used on this website infringes your copyright, please contact us immediately (info@kdj.com) and we will delete it promptly.
-
-
- Consensus 2026 Miami: Web3, Blockchain, Cryptocurrency, NFTs, Metaverse, Conference, May 5th — Where Wall Street Meets the Digital Frontier
- May 01, 2026 at 11:27 pm
- Miami buzzes as Consensus 2026 approaches on May 5th, highlighting Web3, blockchain, crypto, NFTs, and the metaverse's shift from hype to institutional and sustainable reality.
-
-
- Bitcoin Miners Electrify the Grid: Ohio Gas Plant Acquisition Powers Up a New Era for Digital Gold
- Apr 30, 2026 at 10:38 pm
- The Bitcoin mining industry is undergoing a significant transformation, with major players aggressively expanding operations and strategically acquiring energy assets like Ohio gas plants to solidify their future in the digital economy.
-
-
- Solana's Slippery Slope: Price Prediction Points to Resistance Loss and Potential Further Drops
- Apr 30, 2026 at 09:08 pm
- Solana is struggling to break key resistance, signaling potential downside. Repeated rejections at $86-$88, coupled with a broken short-term pattern, point to targets as low as $67, or even $40, as sellers maintain control. Investors should watch critical support levels closely.
-
-
- NYC's New Beat: Staking Systems, USD1, and Governance Drive Crypto's Next Wave
- Apr 30, 2026 at 03:02 pm
- From lucrative USD1 earning events to robust governance models, the crypto sphere is buzzing with innovations reshaping how we engage with digital assets, focusing on long-term commitment and stablecoin utility.
-
- OKX Unveils Agent Payments Protocol: Ushering in a New Era of AI Transactions
- Apr 30, 2026 at 02:53 pm
- OKX launches its Agent Payments Protocol (APP), an open standard for AI-driven commerce, enabling agents to manage full business cycles. Explore the implications for AI transactions and agentic payments.

































