class AwsRdsStatusLookupService {

    public ExternalDatabaseStatus getStatus(AuthenticatedContext ac, DatabaseStack dbStack) {
        AwsCredentialView credentialView = new AwsCredentialView(ac.getCloudCredential());
        String regionName = ac.getCloudContext().getLocation().getRegion().value();
        AmazonRDS rdsClient = awsClient.createRdsClient(credentialView, regionName);

        String dbInstanceIdentifier = dbStack.getDatabaseServer().getServerId();

        DescribeDBInstancesRequest describeDBInstancesRequest = new DescribeDBInstancesRequest().withDBInstanceIdentifier(dbInstanceIdentifier);
        DescribeDBInstancesResult describeDBInstancesResult;
        try {
            describeDBInstancesResult = rdsClient.describeDBInstances(describeDBInstancesRequest);
        } catch (DBInstanceNotFoundException ex) {
            return ExternalDatabaseStatus.DELETED;
        } catch (RuntimeException ex) {
            throw new CloudConnectorException(ex.getMessage(), ex);
        }

        return describeDBInstancesResult.getDBInstances()
                .stream()
                .map(i -> getExternalDatabaseStatus(i.getDBInstanceStatus()))
                .findFirst()
                .get();
    }

}