The following shell script will find the endpoint address of an existing RDS instance in an AWS account. We just need to pass the database instance identifier as the input. This snippet will be very helpful in automation scripts to dynamically find the endpoint address.

I have created this script as part of an EC2 user-data script (bootstrap script) for finding the endpoint address and assigning the value in a config file

#!/usr/bin/env bash

DBINSTANCEIDENTIFIER="my-rds"
ENDPOINT_ADDRESS=$(aws rds describe-db-instances \
    --query 'DBInstances[*].[Endpoint.Address]' \
    --filters Name=db-instance-id,Values=$DBINSTANCEIDENTIFIER \
    --output text \
    )

echo "Endpoint Address --> $ENDPOINT_ADDRESS"