如何访问 swagger.yaml / openapi.yaml 文件中的 AWS SAM 映射

How to access AWS SAM Mapping in swagger.yaml / openapi.yaml files

我在 sam.yaml 文件中声明了一个名为 StageMap 的映射:


AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31

Parameters:
  ProjectName:
    Type: String
  SubProjectName:
    Type: String
  Stage:
    Type: String
    AllowedValues:
      - dev
      - test
      - preprod
      - prod
...

Mappings:
  StageMap:
    dev:
      AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-dev-AuthorizerFunction-1RR2YJ5STBUB6/invocations
    test:
      AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-test-AuthorizerFunction-UQ1EQ2SP5W6G/invocations
    preprod:
      AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-preprod-AuthorizerFunction-UQ1W6EQ2SP5G/invocations
    prod:
      AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-prod-AuthorizerFunction-5STBUB61RR2YJ/invocations

我想在我的 swagger.yaml 中使用这个映射 我尝试了以下方法:

...
x-amazon-apigateway-authorizer:
  type: request
  authorizerUri:
    Fn::FindInMap:
      - 'StageMap'
      - Ref: 'Stage'
      - 'AuthorizerArn

我也试过 this solution 但我遇到了错误 Every Mappings attribute must be a String or a List

能否请您告诉我如何访问 swagger.yaml 中映射中的值之一?谢谢!

我在 AWS SAM docs 中找到以下内容:

You cannot include parameters, pseudo parameters, or intrinsic functions in the Mappings section.

所以我改变了:

AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-dev-AuthorizerFunction-1RR2YJ5STBUB6/invocations

对于:

AuthorizerFunctionName: auth-bk-main-dev-AuthorizerFunction-1RR2YJ5STBUB6

并且在 swagger.yaml 中我使用了以下内容:

x-amazon-apigateway-authorizer:
        type: request
        authorizerUri:
          Fn::Sub:
            - arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AuthorizerFunctionName}/invocations
            - AuthorizerFunctionName:
                Fn::FindInMap:
                  - 'StageMap'
                  - Ref: 'Stage'
                  - 'AuthorizerFunctionName'