LoginSignup
0

More than 5 years have passed since last update.

Serverless Frameworkのリソースの論理IDの命名規則について (ApiGatewayDeployment{randomNumber})

Posted at

1. はじめに

Serverless Frameworkで構築されるAPI Gatewayのリソースに対してserverless.yml内で容易に設定の変更が出来ない.

2. 詳細

やりたいこととしては,Serverless FrameworkでAPI Gatewayのリソースを作成し,そのリソースを参照して,設定(例えばメソッドスロットリングやステージ変数など)を変更したい.

Serverless Frameworkがデフォルトでサポートしていない設定については,serverless.ymlのresourcesのセクションに記述することで,AWS CloudFormationでstackに設定を追加できる.

resourcesとは,Serverless Frameworkのサイトから引用すると下記の部分になる.

serverless.yml
service: service-name
provider: aws
functions:
  ...

resources:
  Resources:
    ProxyResource:
      Type: AWS::ApiGateway::Resource
      Properties:
        ParentId:
          Fn::GetAtt:
            - ApiGatewayRestApi # our default Rest API logical ID
            - RootResourceId
        PathPart: serverless # the endpoint in your API that is set as proxy
        RestApiId:
          Ref: ApiGatewayRestApi
    ProxyMethod:
      Type: AWS::ApiGateway::Method
      Properties:
        ResourceId:
          Ref: ProxyResource
        RestApiId:
          Ref: ApiGatewayRestApi
        HttpMethod: GET # the method of your proxy. Is it GET or POST or ... ?
        MethodResponses:
          - StatusCode: 200
        Integration:
          IntegrationHttpMethod: POST
          Type: HTTP
          Uri: http://serverless.com # the URL you want to set a proxy to
          IntegrationResponses:
            - StatusCode: 200

設定の変更には,Serverless Frameworkで作成されたリソースの論理IDが必要となる.論理IDはServerless Frameworkの命名規則に則って自動的に作成される.Serverless Frameworkの命名規則を見てもらうとわかるが,自動生成される論理IDが予測できるものと,そうでないものがある.予測が出来ないものとは作成される論理IDのルールに{randomNumber}が入っているもので,ここには名前の通りランダムな値が入る.API Gatewayのリソースは論理IDの命名規則が,ApiGatewayDeployment{randomNumber}となっており,論理IDの予測が出来ない.

下記のように問題だと思っている人達がいる.

2.1. 回避策

実施はしていないが下記のような回避先がある模様

Serverless Framework v1.0.0-rc.1でdeployコマンドをフックするプラグインを作る

3. 参考リンク

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
0