How to query for Amazon RDS instance configuration?



  • From within a plpgsql script run on an Amazon RDS Postgres instance, is it possible to get information about instance configuration? How do I retrieve the DB instance ID, ARN (Amazon Resouce Name) or Endpoint of the instance?

    I want to use it as a check inside some plpgsql-script to make a 100% sure it's not going to do its thing on the production database.



  • Unlike the https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html and ECS Tasks ( https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint.html / https://docs.aws.amazon.com/AmazonECS/latest/userguide/task-metadata-endpoint-fargate.html ) there is no metadata service that you are able to query to provide you with those details. The best that you will be able to get would be from system level views that might provide the hostname. However I would use caution with relying on that information as in a fully managed environment failovers and instance replacements happen automatically 99% of the time so the values you query could might be different the next time and may or may not have a standard nomenclature to them.

    The only way to get that information is to make a call to the RDS API endpoint for the cluster and/or instance that you are looking for.

    If you are running the sql via an external process that will connect to the instance you could put those checks as a prerequisite to connecting and running the script. However if you are manually run the script by connecting directly to the instance and hoping to prevent an "oops" action it's going to be up to the person taking the action to check their work.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2