How do I utilize Amazon ElastiCache Serverless with Redis and Memcached in TypeScript?
In this guide, we will configure Amazon ElastiCache Serverless with both Redis and Memcached using Pulumi and TypeScript. We will create the necessary resources, including the ElastiCache clusters for both Redis and Memcached, and configure them to be serverless.
Key Points:
- We will use the
aws-native.elasticache.ServerlessCache
resource to create serverless ElastiCache clusters. - We will configure separate clusters for Redis and Memcached.
- Security groups and subnets will be configured for network access.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsNative from "@pulumi/aws-native";
// Create a VPC
const vpc = new aws.ec2.Vpc("myVpc", {
cidrBlock: "10.0.0.0/16",
enableDnsHostnames: true,
enableDnsSupport: true,
});
// Create subnets
const subnet = new aws.ec2.Subnet("mySubnet", {
vpcId: vpc.id,
cidrBlock: "10.0.1.0/24",
availabilityZone: "us-west-2a",
});
// Create a security group
const securityGroup = new aws.ec2.SecurityGroup("mySecurityGroup", {
vpcId: vpc.id,
ingress: [{
protocol: "tcp",
fromPort: 6379,
toPort: 6379,
cidrBlocks: ["0.0.0.0/0"],
}],
egress: [{
protocol: "tcp",
fromPort: 0,
toPort: 0,
cidrBlocks: ["0.0.0.0/0"],
}],
});
// Create a serverless Redis cluster
const redisCluster = new awsNative.elasticache.ServerlessCache("myRedisCluster", {
engine: "redis",
serverlessCacheName: "myRedisServerlessCache",
subnetIds: [subnet.id],
securityGroupIds: [securityGroup.id],
cacheUsageLimits: {
dataStorage: {
unit: "GB",
maximum: 100,
},
ecpuPerSecond: {
maximum: 1000,
},
},
tags: [
{
key: "Name",
value: "myRedisServerlessCache",
},
],
});
// Create a serverless Memcached cluster
const memcachedCluster = new awsNative.elasticache.ServerlessCache("myMemcachedCluster", {
engine: "memcached",
serverlessCacheName: "myMemcachedServerlessCache",
subnetIds: [subnet.id],
securityGroupIds: [securityGroup.id],
cacheUsageLimits: {
dataStorage: {
unit: "GB",
maximum: 100,
},
ecpuPerSecond: {
maximum: 1000,
},
},
tags: [
{
key: "Name",
value: "myMemcachedServerlessCache",
},
],
});
// Export the endpoint URLs of the clusters
export const redisEndpoint = redisCluster.endpoint;
export const memcachedEndpoint = memcachedCluster.endpoint;
Summary
In this guide, we set up Amazon ElastiCache Serverless clusters for both Redis and Memcached using Pulumi and TypeScript. We configured the necessary VPC, subnets, and security groups to allow network access to the clusters. Finally, we exported the endpoint URLs for both clusters. This setup provides a scalable and serverless caching solution on AWS.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.