X

Redis for .NET Developers – Redis running in AWS ElastiCache

Redis-running-in-AWS-ElastiCache

I wanted to go through the process of Redis running in AWS ElastiCache, since we have already covered Docker, Azure and plain vanilla Redis on Linux Server. Redis in AWS is under the umbrella of ElastiCache, where they offer Redis and Memcached.

There are different type of nodes offered by AWS ElastiCache:

  • Standard
  • Memory Optimized

I wont be going through the AWS offering, since AWS ElastiCache does a good job in explaining the differences between the Nodes.

First you will need to login to your AWS console, once logged in.

  1. Click on the Database Section of ElastiCache

    AWS-ElastiCache

  2. Select the Redis option on the Dashboard Menu

    AWS-ElastiCache-2

  3. Click on Create

    AWS-ElastiCache-3

  4. Select the node that you wish to use. Here I am just selecting small, but feel free to choose which one serves you the best.

    AWS-ElastiCache-4

  5. Select Redis and fill in the Name of the cluster and click Create.

    AWS-ElastiCache-5

  6. The process takes couple of minutes and will complete

    AWS-ElastiCache-6

  7. Once complete you will have a AWS domain name to connect to your Redis

    AWS-ElastiCache-7

AWS does not have the option to see ElastiCache Redis running within its Console like Azure, but one can connect to the endpoint the same way you connect to any Redis instance. As we saw there is a default hostname that is given by AWS to connect to, there is no secret/key pair provided like Azure. The access to the ElastiCache Redis instance is configured through AWS Security Groups, just like connecting to your RDS, EC2 instance.

There are two important items to note when running AWS ElastiCache with Redis:

  1. One cannot set password on the Redis instance. Any EC2 instance in the same security group will have access to your Redis instance.
  2. Connection to the ElastiCache instance is only within the region/VPC

When using StackExchange.Redis you can connect to the Redis instance, the information to connect to AWS ElastiCache is located in the AWS Console under your Redis instance running, one can use the sample code below to connect. (Note: AWS uses Security Group to connect)

private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy(() =>
{
    return ConnectionMultiplexer.Connect("whatever-redis.bd1zu2.0009.usw2.cache.amazonaws.com:6379");
});

public static ConnectionMultiplexer Connection
{
    get
    {
        return lazyConnection.Value;
    }
}

For other Redis topics

  1. Intro to Redis for .NET Developers
  2. Redis for .NET Developer – Connecting with C#
  3. Redis for .NET Developer – String Datatype
  4. Redis for .NET Developer – String Datatype part 2
  5. Redis for .NET Developer – Hash Datatype
  6. Redis for .NET Developer – Redis running in Docker
  7. Redis for .NET Developer – Redis running in Azure
Categories: .NET AWS Redis
Taswar Bhatti:

View Comments (5)

  • Hi ,

    I have done all the setup for redis in aws console .

    and also i have written the code in C# for caching but how to connect to the AWS console redis using c# code.

    my code work fine when installing redis server locally .
    please help me out to resolve this.

    or if you can help me out to connect to redis using aws lambda

  • Hello,

    Do you know if there are issues with Encrypted AWS Redis ElastiCache Cluster while connecting with a .Net Application Framework

    Regards
    Dhriti

    • Depends on what you mean by your question. There should not be any issue if you are using parameter store or KMS to encrypt the connection string and then to use it to connect to Redis, unless you are speaking of encrypting data in redis, If you can be more specific I might be able to help :)

Related Post