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

时间:2018-05-16 10:37:58

标签: swagger aws-api-gateway amazon-cloudformation

我正在研究swagger文件,要在aws apigateway中创建授权器。但那次我会在swagger文件中提到一些函数和api。但它不会影响到Apigateway.Once我删除了堆栈,它会影响APIgateway.If任何改变都没有影响APIgateway.Below我提到了template.yml文件和swagger文件。请任何人帮助解决这个问题。

template.yml文件

AWSTemplateFormatVersion:'2010-09-09'

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

描述:TestApi

资源:

ApiGateway:

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

DriverDeleteF:

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”:“2.0”,

“info”:{

"title": "demo"

},   “host”:“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"
    }
  }
 },

},   “securityDefinitions”:{

"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"
}

} }

1 个答案:

答案 0 :(得分:1)

在DefinitionUri中指定S3 uri时,Cloudformation不会比较s3对象的内容。您可以改为指定相对本地路径,并让cloudi 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

  

AWS :: ApiGateway :: RestApi资源的BodyS3Loc​​ation属性

     

AWS :: Lambda :: Function资源的代码属性

     

AWS :: Serverless :: Function资源的CodeUri属性

     

AWS :: Serverless :: Api资源的DefinitionUri属性

     

AWS :: ElasticBeanstalk :: ApplicationVersion资源的SourceBundle属性

     

AWS :: CloudFormation :: Stack资源的TemplateURL属性

按如下方式部署堆栈:

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