首页 文章

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

提问于
浏览
0

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

template.yml file

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 file content

{

“招摇”:“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"
   }
}

},“definitions”:{

"Empty": {

  "type": "object",

  "title": "Empty Schema"
}

}}

1 回答

  • 1

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

    AWS :: ApiGateway :: RestApi资源的BodyS3Location属性AWS :: Lambda :: Function资源的Code属性AWS :: Serverless :: Function资源的CodeUri属性AWS :: Serverless :: Api资源SourceBundle的DefinitionUri属性AWS :: CloudFormation :: Stack资源的AWS :: ElasticBeanstalk :: ApplicationVersion资源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
    

相关问题