構成
手元端末 → 踏み台@EC2 → 作業ホスト@EC2 → APIGWやRDS
トンネル工事
手元端末から踏み台へのトンネル堀り
% ssh {踏み台ホスト} -p {踏み台ポート} -l {ユーザ} -L 54321:localhost:54321 -L 10443:localhost:10443
踏み台から作業ホストへのトンネル掘り
$ ssh {作業ホスト} -l {ユーザ} -L 54321:{RDSエンドポイント}:5432 -L 10443:{APIGWエンドポイント}:443
手元端末からトンネル経由でRDSに接続
何も考えずlocalhost:54321に接続すればよい。
% psql -h localhost -p 54321 -U postgres postgres
Password for user postgres:
psql (11.9, server 11.8)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
postgres=>
手元端末からトンネル経由でAPI Gateway呼び出し
何も考えずlocalhost:10443にcurlを実行するとcurl側で自主規制された。
% curl https://localhost:10443/test
curl: (60) SSL: no alternative certificate subject name matches target host name 'localhost'
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
「-k」を付けて強制実行したらサーバ側で拒否された。
% curl -k https://localhost:10443/test
{"message":"Forbidden"}
HTTPヘッダに「Host」を付与してあげるとうまくいった。
% curl -k --header 'Host: {APIGWエンドポイントのホスト名}' https://localhost:10443/test
{"result": "OK"}
以上
【参考サイト】

curl: how to specify target hostname for https request
I have a x.example which serves traffic for both a.example and b.example.
x.example has certificates for both a.example and b.example. The DNS for a.example and...