Reputation: 724
I'd like to write a script that snapshots and restores the RDS database associated with my Elastic Beanstalk environment. How can I get the RDS instance id which I'll be plugging into the aws rds create-db-snapshot
and aws rds restore-db-instance-from-db-snapshot
commands?
I know that it can be seen in the Configuration tab in the web interface, but I wanted to get it using a command executed in the shell.
Upvotes: 1
Views: 2075
Reputation: 6906
The most straightforward way that I've found involves the following steps
$ eb ssh {environment-id}
Run the following command from the SSH terminal to get the RDS instance id:
$ sudo /opt/elasticbeanstalk/bin/get-config environment --output YAML | grep RDS_HOSTNAME | sed -n "s/^RDS_HOSTNAME: \([a-z0-9]*\).*$/\1/p"
The above command gets all the available environment variables, including the special ones that start with RDS_
, greps for the RDS_HOSTNAME
variable, and then extracts the value you need with sed
.
Upvotes: 1
Reputation: 298
You can get a history of event this way...
aws elasticbeanstalk describe-events --environment-name your_environment_name
One of the events in your history should include the db-instance-identifier...
{
"ApplicationName": "some-app",
"EnvironmentName": "some-env",
"Severity": "INFO",
"RequestId": "some-ref-id",
"Message": "Created RDS database named: some-db-instance-identifier",
"EventDate": "2017-01-30T23:23:37.734Z"
},
Then you can take that message string and get the DB Instance Identifier to use here...
aws rds create-db-snapshot --db-instance-identifier some-db-instance-identifier --db-snapshot-identifier name-of-snapshot
It's a bit of work. :)
Upvotes: 0
Reputation: 17455
While you can configure an RDS instance when you configure an Elastic Beanstalk application, they are not really tied together. They can both run in a VPC but that's the only real grouping per se. You could easily use the RDS for something else too.
You will likely want to use something like aws rds describe-db-instances
to get the RDS instance information coupled with an instance name (i.e. application1-ebs-rds) to allow you to locate the RDS.
Upvotes: 1