AWS Logo
Menu
Exporting Amazon ElastiCache Backup to Amazon S3

Exporting Amazon ElastiCache Backup to Amazon S3

Exporting ElastiCache backups to Amazon S3 ensures long-term storage, data portability, and integration with other AWS services.

Published Mar 19, 2025

Introduction

Amazon ElastiCache is a fully managed in-memory data store service supporting Redis and Memcached. It provides automated backup functionality, enabling users to restore data in case of failures or migrate it to other environments. Exporting ElastiCache backups to Amazon S3 ensures long-term storage, data portability, and integration with other AWS services.
This guide outlines the steps to export an ElastiCache backup to an Amazon S3 bucket.

Prerequisites

Before proceeding, ensure that you have:
- An Amazon ElastiCache Redis cluster (backups are not supported for Memcached).
- An Amazon S3 bucket for storing the backup.
- Appropriate IAM permissions to allow ElastiCache to write to the S3 bucket.
- AWS CLI or AWS Management Console access.

Step 1: Create an S3 Bucket for Backup Storage

If you haven’t already, create an S3 bucket:
1. Navigate to the Amazon S3 console.
2. Click Create Bucket.
3. Provide a unique bucket name and choose a region.
4. Configure permissions as per your security requirements.
5. Click Create Bucket.

Step 2: Set Up an IAM Role for ElastiCache

ElastiCache needs permissions to write backups to the S3 bucket.

1. Create an IAM Policy

Create a new policy with the following permissions:
Replace backups-product with your actual S3 bucket name.

2. Create an IAM Role

  1. Navigate to the IAM Console.
  2. Click Roles and select Create role.
  3. Choose AWS Service and select ElastiCache.
  4. Attach the policy you created.
  5. Complete the role creation and note the IAM Role ARN.

Step 3: Create and Export a Backup

1. Create a Backup

Using AWS CLI:
aws elasticache create-snapshot \
--cache-cluster-id your-cluster-id \
--snapshot-name my-backup
Replace your-cluster-id with your ElastiCache cluster ID.
Using AWS Console:
1. Navigate to ElastiCache.
2. Select your Redis cluster.
3. Click Backups > Create Backup.
4. Enter a name and confirm.

2. Export Backup to S3

Once the backup is created, export it to S3:
Replace:
- your-bucket-name with the target S3 bucket.
- your-account-id with your AWS account ID.
- your-role-name with the IAM role you created.

Step 4: Advanced Python Script to Export Redis Data to S3

The following Python script efficiently exports all Redis keys and values (including different data types) to Amazon S3:

Step 5: Automate with AWS Lambda

  1. Deploy the script as an AWS Lambda function.
  2. Add IAM permissions to allow writing to S3.
  3. Schedule the Lambda function using CloudWatch Events.

Diagram

For further details, refer to the AWS Documentation.

Conclusion

Exporting Amazon ElastiCache backups to S3 is essential for long-term data storage, disaster recovery, and migration purposes. By setting up the correct IAM permissions and following the outlined steps, you can seamlessly integrate ElastiCache with S3 for efficient backup management.
 

Comments