gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:37:04 24 4
gpt4 key购买 nike

我正在处理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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com