amazon-web-services - AWS CloudFormation API GatewayV2 路由创建

标签 amazon-web-services aws-cloudformation aws-api-gateway

我正在创建一个模板,以使用 apigatewayv2 创建 http api。

我在模板中的 API 定义是:

sfHttpApi:
    Type: AWS::ApiGatewayV2::Api
    DependsOn: sfLambdaFunction
    Properties:
      Name: !Sub sfHttpAPI-${Region}-${Env}
      ProtocolType: HTTP
      Target: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${sfLambdaFunction}/invocations
      CredentialsArn: !GetAtt sfApiGatewayRole.Arn

  sfApiTriggerLambdaPermission:
    Type: "AWS::Lambda::Permission"
    Properties:
      Action: lambda:InvokeFunction
      FunctionName: !GetAtt sfLambdaFunction.Arn
      Principal: apigateway.amazonaws.com
      SourceArn: !Sub 'arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${sfHttpApi}/' 

  sfApiLambdProxyIntegration:
    Type: "AWS::ApiGatewayV2::Integration"
    Properties:
      Description: Lambda Integration
      ConnectionType: INTERNET
      IntegrationMethod: POST
      IntegrationUri: !Sub  "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${sfLambdaFunction.Arn}/invocations"
      PayloadFormatVersion: '1.0'
      ApiId: !Ref sfHttpApi
      IntegrationType: AWS_PROXY

  sfRoute:
    Type: 'AWS::ApiGatewayV2::Route'
    DependsOn:
      - sfApiLambdProxyIntegration
    Properties:
      ApiId: !Ref sfHttpApi
      RouteKey: 'POST/'  **??? This is the part I dont know how to set**
      AuthorizationType: NONE
      Target: !Join 
        - /
        - - integrations
          - !Ref sfApiLambdProxyIntegration

我尝试以不同的方式在路由定义中设置routekey,但在创建堆栈时出现错误:

The provided route key is not formatted properly for HTTP protocol. Format should be " /" or "$default" (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: 53198c85-fc41-4c76-89c4-7d2db7a7a5b6)

如何设置routekey?

最佳答案

POST后面加一个空格,即POST/

关于amazon-web-services - AWS CloudFormation API GatewayV2 路由创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60768983/

相关文章:

javascript - Amazon Connet 的 getCurrentMetricData 不是函数

aws-cloudformation - CloudFormation 中的 AWS API Gateway 方法响应 - 输出直通 : No

node.js - HTTP 请求问题 内部服务器错误

c# - TestWebACL 错误原因 : Your statement has multiple values set for a field that requires exactly one value

amazon-web-services - 具有 2 个 AWS 账户的 AWS CodePipeline 最佳实践

amazon-web-services - 如何在 AWS CloudFormationTemplate 中引用 Lambda 的 AWS GlobalSecondaryIndex 名称

post - 增加 Amazon API Gateway 的最大 POST 大小

ruby-on-rails - 使用 Rails 显示存储在 Amazon S3 上的 PDF

python - 使用相同参数调用其他 lambda 的 Aws Lambda?

amazon-web-services - 使用 ECS-CLI 将多容器 docker 应用程序部署到 AWS ECS Fargate