如何删除刻度线在AWS API上使用Lambda代理集成

问题描述

我使用sam模板创建api + lambdas,但是我面临着一个问题,即如何删除刻度线在sam模板enter image description here aws api中使用Lambda Proxy集成??????

解决方法

您不能使用SAM来做到这一点,因为它是有限的,并且他们选择保持它的轻便和最小化(根据我的经验,在Github上与他们争论的还有其他功能)。您可以做的是将SAM与cloudformation类型混合使用:

ApiGatewayRestApi:
  Type: AWS::ApiGateway::RestApi
  Properties:
    ApiKeySourceType: HEADER
    Description: An API Gateway with a Lambda Integration
    EndpointConfiguration:
      Types:
        - EDGE
    Name: lambda-api

ApiGatewayResource:
  Type: AWS::ApiGateway::Resource
  Properties:
    ParentId: !GetAtt ApiGatewayRestApi.RootResourceId
    PathPart: 'lambda'
    RestApiId: !Ref ApiGatewayRestApi

ApiGatewayMethod:
  Type: AWS::ApiGateway::Method
  Properties:
    ApiKeyRequired: false
    AuthorizationType: NONE
    HttpMethod: POST
    Integration:
      ConnectionType: INTERNET
      Credentials: !GetAtt ApiGatewayIamRole.Arn
      IntegrationHttpMethod: POST
      PassthroughBehavior: WHEN_NO_MATCH
      TimeoutInMillis: 29000
      Type: AWS
      Uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations'
    OperationName: 'lambda'
    ResourceId: !Ref ApiGatewayResource
    RestApiId: !Ref ApiGatewayRestApi

请注意,integration type设置为AWS而不是AWS_PROXY。有关CFT类型的更多信息,请参见documentation。还需要注意的重要一点是,如果不使用代理,则可能需要提供模型和要求/要求模板。同样,SAM CLI local不适用于req / res模板。