DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • How to Backup SQL Server RDS to an S3 Bucket
  • Optimizing Cost and Performance in AWS EC2 Backup
  • Simplify Database Geo-Redundancy Backup With Cloud Storage Services
  • 7 Invaluable Advantages of Using Amazon RDS

Trending

  • Memory Leak Due to Time-Taking finalize() Method
  • AI-Driven Root Cause Analysis in SRE: Enhancing Incident Resolution
  • Developers Beware: Slopsquatting and Vibe Coding Can Increase Risk of AI-Powered Attacks
  • AWS to Azure Migration: A Cloudy Journey of Challenges and Triumphs
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Creating a Lambda-based Automated Backup Job for AWS RDS

Creating a Lambda-based Automated Backup Job for AWS RDS

Check out this tutorial that will create an automated backup system to overcome the limitations of the built-in auto backups feaure.

By 
Muhammad Ali user avatar
Muhammad Ali
·
Jul. 10, 18 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
12.0K Views

Join the DZone community and get the full member experience.

Join For Free

This article helps in creating an automated RDS backup function in Lambda that uses AWS SDK Java.

Why Is the Auto Backups Feature of RDS Not Enough?

Before we go to the step-by-step guide we should know why the default automated backup feature of RDS provided by AWS is not enough.

There are two reasons for that:

1. The retention period of backups supported by RDS auto backup feature is 35 days at max which means you can keep 35-day-old backup only. What if you want to keep backups older than 35 days?

2. Many organizations require a sophisticated backup routine where they prefer to take backups on selected days of the month. Some organization prefer one backup per week and some prefer more than one backups per day. This kind of customizable and sophisticated routine is not achievable using the auto backup feature of RDS.

Prerequisites

We assume you already have Java, Eclipse, AWS eclipse toolkit with SDK all configured and running. Here are some useful links if you don't:

Setting Up AWS Eclipse Toolkit

Create, upload and invoke Lambda function

Try creating a HelloWorld Lambda function to make sure everything is working fine. Once you have your handleRequest method ready and working follow the steps below. handleRequest is the method that we need to override and within it, provide the functionality of our Lambda function

Steps

1.  Get the access key and secret key from IAM console if you are using an IAM user to create an and run the Lambda function. If you are using root user download the keys from ‘My Security Credentials”.

2.  Get the unique identifier for the target RDS instance from RDS console.

3.  Know the region identifier for example us-west-2

4.  Now create following String constants in your Request Handler class

//alphanumeric accesskey and secretkey private 
static final String accesskey = "xxxx"; 
private static final String secretkey = "xxxxx"; 
//RDS instance identifier 
private static final String db_instance_identifier = "xyz"; 
//region private static final String region = "xx-xxxx-x";

5.  Create a unique identifier to be assigned later to the backup snapshot

String date = LocalDateTime.now().toString(); 
//generated data has : character that is not supported to be used in the unique identifier, so 
//replacing it with - sign. 
String db_snapshot_id = "RDS-snapshot-"+date.replace(':','-').replace('.', '-');

6.  Use BasicAWSCredentials  to provide Lambda code the authentication to connect to RDS and take the backup snapshot. Create AWSStaticCredentialsProvider   object out of BasicAWSCredentials .

BasicAWSCredentials basic_aws_credentials = new BasicAWSCredentials(accesskey,secretkey); 
AWSCredentials aws_credentials = (AWSCredentials)basic_aws_credentials; 
AWSStaticCredentialsProvider aws_static_credentials_provider = AWSStaticCredentialsProvider(aws_credentials)

7.  We need to create an object that stores all information about the request we are going to make to the RDS instance for the creation of backup. So for this, we create a CreateDBSnapshotRequest  object.

CreateDBSnapshotRequest create_snapshot_request = new CreateDBSnapshotRequest(db_snapshot_id, db_instance_id);

8.  Now create the AmazonRDSClient object that is actually used to create the backup snapshot and also allows you to perform many other possible RDS related tasks

AmazonRDSClient rdsclient = (AmazonRDSClient) AmazonRDSClientBuilder.standard().withCredentials(aws_static_credentials_provider).withRegion(region).build(); 
DBSnapshot snapshot = rdsclient.createDBSnapshot(create_snapshot_request);

9.   Build and Deploy your Lambda project.

AWS Backup

Opinions expressed by DZone contributors are their own.

Related

  • How to Backup SQL Server RDS to an S3 Bucket
  • Optimizing Cost and Performance in AWS EC2 Backup
  • Simplify Database Geo-Redundancy Backup With Cloud Storage Services
  • 7 Invaluable Advantages of Using Amazon RDS

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!