LoginSignup
1
0

More than 5 years have passed since last update.

AWS CloudFormationでデプロイしたAPI Gatewayが更新されない

Last updated at Posted at 2019-03-18

はじめに

ある特定のケースでデプロイの結果がAPI Gatewayに反映されない場合があり、原因はわからないが解決はできたので覚書

解決策

AWSコンソールから何も変更を加えず手動でデプロイのアクションをする

状況

  1. CloudFormationのテンプレートにAPI GatewayのSwaggerファイルを読み込んでいる
  2. API Gatewayのmethod.response.header.Access-Control-Allow-Origin:のみ変更しデプロイする
  3. デプロイ完了後、確認するも設定が反映されていない

使用したテンプレートの抜粋

template.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: ...
Resources:
  Api:
    Type: AWS::Serverless::Api
    Properties:
      StageName: dev
      DefinitionBody:
        Fn::Transform:
          Name: AWS::Include
          Parameters:
            Location: !Sub s3://${CfnBucketName}/${AWS::StackName}/src/api/swagger.yaml

swagger.yaml
swagger: "2.0"
info:
  version: "2018-09-04T22:25:14Z"
  title: "title"
basePath: "/dev"
schemes:
- "https"

paths:
  /token:
    options:
      consumes:
      - "application/json"
      produces:
      - "application/json"
      responses:
        200:
          description: "200 response"
          schema:
            $ref: "#/definitions/Empty"
          headers:
            Access-Control-Allow-Origin:
              type: "string"
            Access-Control-Allow-Methods:
              type: "string"
            Access-Control-Allow-Headers:
              type: "string"
      x-amazon-apigateway-integration:
        responses:
          default:
            statusCode: "200"
            responseParameters:
              method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
              method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
              method.response.header.Access-Control-Allow-Origin:
                Fn::Sub: "'${AllowOrigins}'"
        requestTemplates:
          application/json: "{\"statusCode\": 200}"
        passthroughBehavior: "when_no_match"
        type: "mock"

おわりに

今のところ2回同じ操作をして2回とも同じ現象になっている
リソースやメソッドの追加・削除では起きたことがないので、メソッドのプロパティの変更の場合に起きるんだろうか
気が向いたら調査するかも

1
0
0

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
1
0