Search code examples
amazon-rdsamazon-aurora

AWS RDS: How to get hold of the Current Activity / Number of Connections?


Using the AWS RDS console it is very easy to see the number of connections to an instance in the "Current Activity" column: enter image description here

How do I get this information from the aws cli? As far as I can tell, aws rds describe-db-instances does not seem to have this particular piece of information.

NOTE: For my purposes, it would be enough to know if there are any connections.


Solution

  • For metrics, you should be using the aws cloudwatch tool. To get the number of database connections currently, you could use something like this:

    aws cloudwatch get-metric-statistics --namespace AWS/RDS
    --metric-name DatabaseConnections --start-time 2018-06-14T16:00:00Z
    --end-time 2018-06-14T16:01:00Z --period 60 --statistics "Maximum"
    --dimensions Name=DBInstanceIdentifier,Value=your-db-identifier
    

    You'll need to combine it with code or a script to insert the correct --start-time and --end-time values.