LoginSignup
7

More than 5 years have passed since last update.

AWS Serverless Application Model (SAM)でCORS設定

Posted at

この記事は

SAMに従ったCloudformationテンプレにて、Api GatewayのCORSの設定方法がわからなかったのでメモします。

設定方法

こちらに書いてあります。
serverless-application-model/2016-10-31.md at master · awslabs/serverless-application-model

以下例のようにGlobal Sectionへ設定を書きます。例ではwww.example.comからのアクセスのみ許可します。

Globals:
  Api:
    Cors: "'www.example.com'"

少々トラップなのは、LambdaのEventとして設定しているApi Eventには設定できないようです。これで少しハマりました。

また、Corsに対応する値は"'hoge'"のように、ダブルクォーテーションとシングルクォートの二重にしないとAPIアクセス時エラーになります。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7