はじめに AWSでサーバーレスアーキテクチャのSPAサイトを組むにあたって、フロントエンドをS3(+CloudFront)から配信し、バックエンドをAPI Gatewayに置くのは一般的な構成だと思います。 フロントエンドのサイトとバックエンドのAPIで二つのドメインで運用することもできますが、前段にCloudFrontを置いて一つのドメインから両オリジンにアクセスができる構成を作ってみます。 構成図にするとこんな感じ。 S3 設定はすべてデフォルト。 API Gateway REST APIを作成。 わざわざLambdaを作るのも面倒なのでMockを使って仮のレスポンスを返します。 APIをデプロイします。ステージ名は「api」とします。 得られたエンドポイントからAPIを呼んでみます。 $ curl https://XXXXXXXXXX.execute-api.ap-northeast