swagger 文件内容未在 aws apigateway 中更新

标签 swagger aws-api-gateway aws-cloudformation

我正在处理swagger文件,要在aws apigateway中创建授权者。但是这次我会在swagger文件中提到一些函数和api。但是它不会在Apigateway中生效。一旦我删除了堆栈,它就会生效APIgateway。如果有任何更改,不会影响 APIgateway。下面我提到了 template.yml 文件和 swagger 文件。请任何人帮助解决这个问题。

template.yml 文件

AWSTemplateFormat版本:'2010-09-09'

转换:AWS::Serverless-2016-10-31

描述:TestApi

资源:

API网关:

Type: AWS::Serverless::Api
Properties:
  StageName: Prod
  DefinitionUri: s3://devdeliforcemumbailambda/swagger-json-testapi.json

驱动程序删除F:

Type: AWS::Serverless::Function
Properties:
  FunctionName: driver_delete_fun
  Handler: index.handler
  Runtime: nodejs8.10
  CodeUri: build/authorizer.zip
  Events:
    GetApi:
      Type: Api
      Properties:
        Path: /driver
        Method: delete

swagger 文件内容

{

“Swagger ”:“2.0”,

“信息”:{

"title": "demo"

}, “主机”:“rl0cg75uff.execute-api.ap-south-1.amazonaws.com”,

“basePath”:“/Prod”,

“方案”:[

"https"

],

“路径”:{

"/driver": {

  "delete": {
    "produces": [
      "application/json"
    ],
    "responses": {
      "200": {
        "description": "200 response",
        "schema": {
          "$ref": "#/definitions/Empty"
        }
      }
    },
    "security": [
      {
        "CognitoAuth": []
       }
    ],
    "x-amazon-apigateway-integration": {
      "uri": "arn:aws:apigateway:ap-south-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-south-1:539977196287:function:driver_delete_fun/invocations",
      "responses": {
        "default": {
          "statusCode": "200"
        }
      },
      "passthroughBehavio r": "when_no_match",
      "httpMethod": "POST",
      "contentHandling": "CONVERT_TO_TEXT",
      "type": "aws"
    }
  }
 },

}, “安全定义”:{

"CognitoAuth": {
  "type": "apiKey",
  "name": "Authorization",
  "in": "header",
  "x-amazon-apigateway-authtype": "cognito_user_pools",
  "x-amazon-apigateway-authorizer": {
    "providerARNs": [
      "arn:aws:cognito-idp:ap-south-1:539977196287:userpool/ap-south-1_6j7axGXVm"
    ],
    "type": "cognito_user_pools"
  }
},
"lambdaAuth":{
  "type": "apiKey",
  "name": "Authorization",
  "in": "header",
  "x-amazon-apigateway-authtype": "custom",
  "x-amazon-apigateway-authorizer": { 
     "authorizerUri":  "arn:aws:apigateway:ap-south-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-south-1:539977196287:function:my-service-dev-hello/invocations",
     "authorizerResultTtlInSeconds":1,
      "identitySource": "method.request.header.Authorization",
      "type": "request"
   }
}

}, “定义”:{

"Empty": {

  "type": "object",

  "title": "Empty Schema"
}

} }

最佳答案

当您在 DefinitionUri 中指定 S3 uri 时,Cloudformation 不会比较 s3 对象的内容。您可以指定一个相对本地路径,并让 cloudformation cli 为您上传它,就像通常处理函数代码一样。然后,Cloudformation 将在 s3 对象键中使用您的文件哈希,因此每次包含更改时都会有不同的 DefinitionUri 和 CodeUri。

因此,不要使用这些:

DefinitionUri: s3://devdeliforcemumbailambda/swagger-json-testapi.json
CodeUri: build/authorizer.zip

这样做:

DefinitionUri: ./swagger-json-testapi.json
CodeUri: ./authorizer-code-directory

我写的内容适用于以下内容:( up to date docs here )

BodyS3Location property for the AWS::ApiGateway::RestApi resource

Code property for the AWS::Lambda::Function resource

CodeUri property for the AWS::Serverless::Function resource

DefinitionUri property for the AWS::Serverless::Api resource

SourceBundle property for the AWS::ElasticBeanstalk::ApplicationVersion resource

TemplateURL property for the AWS::CloudFormation::Stack resource

按如下方式部署堆栈:

aws cloudformation package --template-file template.yaml --s3-bucket devdeliforcemumbailambda --output-template-file packaged-template.yaml

aws cloudformation deploy --capabilities CAPABILITY_NAMED_IAM --stack-name test-swagger --template-file packaged-template.yaml

关于swagger 文件内容未在 aws apigateway 中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50368648/

相关文章:

swagger - 我可以使用 Swagger 指示参数值的正则表达式要求吗?

amazon-web-services - 如何通过 API 网关从 lambda 正确返回二进制文件(图像)

javascript - VPC下Lambda访问Api Gateway

amazon-web-services - 如何获取 aws :lambda function as a text? 的 Uri

ansible - 使用 Ansible Cloudformation 模块配置 CoreOS 集群

从 swagger-codegen 生成的 python 服务器 stub 根本无法在本地工作

annotations - 整个响应的声明是否可以在 swagger-php 中重用?

aws-cloudformation - CloudFormation 给出 "Invalid template property or properties"错误

amazon-web-services - AWS 云信息 : Set up ECS cluster with parameters

java - 用 Swagger 表示 ISO 8601 年月日期文档