ShaiNe Ram
ShaiNe Ram

Reputation: 507

AWS RDS snapshot by Java Code Example

I have an RDS PostgreSQL Instance. Inside the instance I have Databases and tables. Daily I need to update my db through lambda java function. I am done this and works fine. But before updating my table from my lambda java function I need to take a snapshot of the RDS PostgreSQL instance from my lamnda java code. Is it possible? Please direct me to write the code for the same?

Upvotes: 0

Views: 515

Answers (1)

ShaiNe Ram
ShaiNe Ram

Reputation: 507

To create a snapshot of the RDS PostgreSQL instance from my lamnda java code is like below. First you have to give a permission for creating snapshot to your IAM Role.

Go to IAM Management Console --> Roles --> Select your role and add permission 'RDS-access-for-creating-snapshot'.

After giving permission use below code to perform snapshot creation.

CreateDBSnapshotRequest snapShotrequest = new CreateDBSnapshotRequest().withDBSnapshotIdentifier("new-snapshotname-"+System.currentTimeMillis()).withDBInstanceIdentifier("currentdbidentifier");
DBSnapshot snapShotresponse = rdsclient.createDBSnapshot(snapShotrequest);
System.out.println("SnapShot Created Successfully");

Upvotes: 1

Related Questions