【问题标题】:Passing AWS region and account ID to swagger将 AWS 区域和账户 ID 传递给 swagger
【发布时间】:2018-02-27 04:34:31
【问题描述】:

我正在使用 AWS SAM 定义我的 API Gateway API

ApiGatewayApi:
  Type: AWS::Serverless::Api
  Properties:
    DefinitionUri: swagger.yml
    StageName: prod
    Variables:
      Region: !Ref AWS::Region
      AccountId: !Ref AWS::AccountId
      Ec2Index: !Ref Ec2Index
      AuthLogin: !Ref AuthLogin
      Ec2Patch: !Ref Ec2Patch
      AutoScalingIndex: !Ref AutoScalingIndex
      AutoScalingPatch: !Ref AutoScalingPatch
      AutoScalingScale: !Ref AutoScalingScale

在我的招摇文件中:

路径: /身份验证/会话: 邮政: 产生: - 应用程序/json x-amazon-apigateway 集成: uri:arn:aws:apigateway:ap-southeast-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-1:598545985414:function:${stageVariables.AuthLogin}/invocations passthroughBehavior:when_no_match http方法:POST 类型:aws_proxy 回复: 200: 描述:应用令牌 401: 描述:401 403: 描述:403

AWS CloudFormation 错误提示

导入期间发现错误:无法为路径“/auth/session”的资源集成“POST”:Lambda 函数 ARN 必须位于同一账户中无法为路径“/autoscaling”的资源集成“GET” ':Lambda 函数 ARN 必须在同一账户中路径“/autoscaling/{groupName}/scale”:Lambda 函数 ARN 必须在同一个账户中 无法为路径“/ec2”的资源在“GET”上进行集成:Lambda 函数 ARN 必须在同一账户中 无法进行集成路径“/ec2/{id}”中资源的“PATCH”:Lambda 函数 ARN 必须在同一账户中

好像我的 ARN 无效。一旦我删除了变量,这个问题就解决了。这里有什么问题?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    截至目前,swagger 不允许在阶段变量中使用 AccountId。这是 API 网关的限制。

    您可以通过仅对函数名称使用阶段变量并将其余部分拼凑在一起来解决此问题,如下所示:

    //does not get passed in. This is just a placeholder for the stage variable
    Parameters: 
        ApiFunctionName:
            Type: String
            Description: Function name of the api lambda function
            Default: ${stageVariables.yourFunctionNameVar}
    
    //in your gateway path   
        x-amazon-apigateway-integration:
            httpMethod: POST
            type: aws_proxy
            uri: 
              !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${ApiFunctionName}/invocations"
    

    【讨论】:

      【解决方案2】:

      Passing variables 到 swagger 目前无法从 SAM 模板执行,但您可以将模板文件中的整个 swagger 文件复制为 DefinitionBody 并以相同的方式引用变量 提供的 swagger 定义不是巨大的

      SAM 模板目前限制为 51.2 KB

      【讨论】:

        猜你喜欢
        • 2021-12-13
        • 2017-09-13
        • 1970-01-01
        • 1970-01-01
        • 2021-12-07
        • 1970-01-01
        • 1970-01-01
        • 2016-11-28
        • 1970-01-01
        相关资源
        最近更新 更多