@yy0706

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

【AWS】プライベートDNSを使って、実在するAPIへのリクエストをAPI Gatewayに向けたい

解決したいこと

【AWS】プライベートDNSを使って、実在するAPIへのリクエストをAPI Gatewayに向けたい

名前解決はできるが、API Gatewayへリクエストが届かずに403のエラーが返ってきてしまう。
原因のあたりについて、何かご教授いただきたいです。

発生している問題・エラー

"{\"message\":\"Forbidden\"}"

該当するソースコード

exports.handler = async (event) => {
    // 実在するAPIのURL
    const api_url = 'https://restcountries.com/v3.1/name/aruba?fullText=true'
    const hostname = new URL(api_url).hostname;
    const path = new URL(api_url).pathname + new URL(api_url).search;
    
    const options = {
        hostname: hostname, 
        port: 443,
        path: path,
        method: 'GET',
        rejectUnauthorized: false  // SSL証明書の検証を無効化
      };
    const res = await req(options)
        .catch(err => err)
    console.log(res);
    return {
        api_url,
        res
    }
}

自分で試したこと

以下の環境をAWSにて構築しました。

①VPC作成
 DNS 解決
 →有効
 IPv4 CIDR
 →10.0.0.0/24
 DNS ホスト名
 →有効
②実在する外部APIへのリクエストを送信するlambdaをVPCに配置
③API Gatewayへ向けるためのエンドポイントを作成
 セキュリティインバウンドルール
 →全許可
③外部APIのドメインでRoute53のホストゾーン作成 
④Aレコードを作成:③で作成したエンドポイント(エイリアス)を値に指定
⑤API Gateway作成
 エンドポイントに③で作成したものを指定
リソースポリシー全許可
POSTメソッドを作成して別のlambda関数に統合

### わかっていること
 ・Route53のログから、VPCのサブネットのIPが解決されていることは確認できた。
・ApiGatewayのログは、吐き出されていないため、おそらくApiGatewayにたどり着く前に何か起きている
 ・直接ApiGatewayのInvoke URLへリクエストしたところ、エラーにはならなかった

0 likes

No Answers yet.

Your answer might help someone💌