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?
Asked
Active
Viewed 432 times
0
-
did you try [`createDBSnapshot()`](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/rds/AmazonRDS.html#createDBSnapshot-com.amazonaws.services.rds.model.CreateDBSnapshotRequest-)? – Sharon Ben Asher Jan 25 '18 at 12:38
-
Thanks for your reply – ShaiNe Ram Jan 29 '18 at 10:35
-
I tried but I am getting errors. I used below code CreateDBSnapshotRequest snapShotrequest = new CreateDBSnapshotRequest().withDBSnapshotIdentifier("new-db-snapshot").withDBInstanceIdentifier("mydb"); DBSnapshot snapShotresponse = rdsclient.createDBSnapshot(snapShotrequest); System.out.println(snapShotresponse); – ShaiNe Ram Jan 30 '18 at 15:56
-
@Sharon Ben Asher yeh.. it was prfectly right. I give rds accesspermission to my role and it works fine now. – ShaiNe Ram Feb 05 '18 at 05:26
1 Answers
1
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");

ShaiNe Ram
- 395
- 2
- 6
- 19