gpt4 book ai didi

aws-cloudformation - 在 AWS::Serverless::Api 中将 API key 源设置为 Authorizer

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

我有一个通过 CloudFormation AWS::Serverless::Api 对象定义的 API。我需要它从其自定义授权者处获取使用计划 key ,相当于 Setting ApiKeySourceType to AUTHORIZER on an AWS::ApiGateway::RestApi 。如何做到这一点?

这是我当前使用的定义,包括从正确配置的 API 导出的 OpenAPI 定义。我确实认为奇怪的是,即使将配置设置为 AUTHORIZER 后,x-api-key 仍然列在 api_key 中。

  RestApi:
Type: AWS::Serverless::Api
Properties:
Name: !Sub ${AWS::StackName}-API
StageName: !Ref ApiStageName
MethodSettings:
- CachingEnabled: false
DataTraceEnabled: false
HttpMethod: '*'
LoggingLevel: INFO
MetricsEnabled: true
ResourcePath: '/*'
ThrottlingBurstLimit: !Ref ThrottlingBurstLimit
ThrottlingRateLimit: !Ref ThrottlingRateLimit
AccessLogSetting:
DestinationArn: !GetAtt ApiLogs.Arn
# format is copied from an example generated by the web console
Format: '{ "requestId":"$context.requestId", "ip": "$context.identity.sourceIp", "requestTime":"$context.requestTime", "httpMethod":"$context.httpMethod","routeKey":"$context.routeKey", "status":"$context.status","protocol":"$context.protocol", "responseLength":"$context.responseLength" }'
CacheClusterEnabled: false
TracingEnabled: true
DefinitionBody: !Sub |
openapi: "3.0.1"
paths:
/v2/oauth2/token:
post:
x-amazon-apigateway-integration:
connectionId: "${RestApiVpcLink}"
httpMethod: "POST"
uri: "http://${VPCLinkLB.DNSName}/v2/oauth2/token"
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
type: "http_proxy"
/{proxy+}:
x-amazon-apigateway-any-method:
parameters:
- name: "proxy"
in: "path"
required: true
schema:
type: "string"
security:
- LambdaAuthorizer: []
- api_key: []
x-amazon-apigateway-integration:
connectionId: "${RestApiVpcLink}"
httpMethod: "ANY"
uri: "http://${VPCLinkLB.DNSName}/{proxy}"
requestParameters:
integration.request.path.proxy: "method.request.path.proxy"
passthroughBehavior: "when_no_match"
connectionType: "VPC_LINK"
type: "http_proxy"
components:
securitySchemes:
LambdaAuthorizer:
type: apiKey
name: Authorization
in: header
x-amazon-apigateway-authtype: custom
x-amazon-apigateway-authorizer:
authorizerUri: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GatewayAuthorizerLambda.Arn}/invocations"
authorizerResultTtlInSeconds: 300
identityValidationExpression: "Bearer .*"
type: "token"
api_key:
type: "apiKey"
name: "x-api-key"
in: "header"

我主要使用 Serverless::Api 而不是它的组件 ApiGateway 对象,因为我发现阶段/部署否则会非常令人头痛。

最佳答案

x-amazon-apigateway-api-key-source: AUTHORIZER 需要添加为 openapi: "3.0.1" 的同级。该 openAPI 扩展记录在 here 中.

看起来阶段导出中一定存在错误,导致该错误丢失。

关于aws-cloudformation - 在 AWS::Serverless::Api 中将 API key 源设置为 Authorizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72294914/

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