简体   繁体   English

AWS Cloudformation Lambda + API 网关 V2:无法部署 API,因为此 API 中不存在路由

[英]AWS Cloudformation Lambda + API Gateway V2: Unable to deploy API because no routes exist in this API

I'm trying to create a API Gateway HTTP API + Lambda integration using CloudFormation, but I'm stuck on this error:我正在尝试使用 CloudFormation 创建一个 API Gateway HTTP API + Lambda 集成,但我遇到了这个错误:

Unable to deploy API because no routes exist in this API (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: f606986f-d3e6-4dfd-bc20-77011b15a3f9; Proxy: null)无法部署 API,因为此 API 中不存在路由(服务:AmazonApiGatewayV2;状态代码:400;错误代码:BadRequestException;请求 ID:f606986f-d3e6-4dfd-bc20-77011b15a3f9;代理:null)

Here's my CloudFormation template:这是我的 CloudFormation 模板:

AWSTemplateFormatVersion: 2010-09-09

Resources:

  LambdaRole:
    Type: AWS::IAM::Role
    Properties:
      Policies:
        - PolicyName: LambdaPolicy
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Action:
                  - 'logs:CreateLogGroup'
                  - 'logs:CreateLogStream'
                  - 'logs:PutLogEvents'
                Resource:
                  - 'arn:aws:logs:*:*:*'
                Effect: Allow
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Action:
              - sts:AssumeRole
            Effect: Allow
            Principal:
              Service:
                - lambda.amazonaws.com

  Lambda:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: 'getFruit'
      Role: !GetAtt LambdaRole.Arn
      Handler: index.handler
      Runtime: nodejs16.x
      MemorySize: 128
      Code:
        ZipFile: |
          exports.handler = async (event) => {
            const response = {
              body: JSON.stringify([
                { id: 1, name: 'banana', price: 1 },
                { id: 2, name: 'pineapple', price: 2 },
              ]),
              statusCode: 200
            }
            return response
          }

  LambdaInvokePermission:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName: !Ref Lambda
      Action: "lambda:InvokeFunction"
      Principal: apigateway.amazonaws.com

  LambdaIntegration:
    Type: AWS::ApiGatewayV2::Integration
    Properties:
      ApiId: !Ref MyApiGateway
      Description: Lambda proxy integration
      IntegrationType: AWS_PROXY
      IntegrationMethod: POST
      PayloadFormatVersion: "2.0"
      IntegrationUri: !Sub 'arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Lambda.Arn}/invocations'

  MyApiGateway:
    Type: AWS::ApiGatewayV2::Api
    Properties:
      Name: "MyApiGateway"
      ProtocolType: "HTTP"

  MyApiGatewayStage:
    Type: AWS::ApiGatewayV2::Stage
    Properties:
      AutoDeploy: true
      DeploymentId: !Ref MyApiGatewayDeployment
      StageName: '$default'
      ApiId: !Ref MyApiGateway
  
  MyApiGatewayDeployment:
    Type: AWS::ApiGatewayV2::Deployment
    Properties:
      ApiId: !Ref MyApiGateway

  MyApiRoute:
    Type: AWS::ApiGatewayV2::Route
    Properties:
      ApiId: !Ref MyApiGateway
      RouteKey: "GET /"
      AuthorizationType: NONE
      Target: !Join
        - /
        - - integrations
          - !Ref LambdaIntegration

Try adding a DependsOn properties to the deployment for the routes you create.尝试将DependsOn属性添加到您创建的路由的部署中。

  MyApiGatewayDeployment:
    Type: AWS::ApiGatewayV2::Deployment
    DependsOn:
      - MyApiRoute
    Properties:
      ApiId: !Ref MyApiGateway

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 terraform 中使用 lambda 别名和阶段变量在 AWS Api Gateway v2 (http) 中进行集成 - How to make integrations in AWS Api Gateway v2 (http) with lambda alias and stage variables in terraform AWS v1 vs v2 API 用于在 AWS 上列出 API API 网关为相同的 API 网关实例返回不同的数据 - AWS v1 vs v2 API for listing APIs on AWS API Gateway return different data for the same API Gateway instance AWS API Gateway 和 Lambda 返回图像 - AWS API Gateway and Lambda to return image Websocket 连接使用 AWS Lambda + API 网关 - Websocket connection using AWS Lambda + API Gateway AWS CDK - API 网关 lambda 调用 - AWS CDK - API gateway lambda invoke 如何使用AWS签名授权 4 -> API 网关 -> Lambda - How to authorize with AWS signature 4 -> API Gateway -> Lambda 无法在 API 网关控制台上测试 Lambda 集成 - Unable to test Lambda Integration on API Gateway Console aws api网关和lambda函数超时问题 - Aws api gateway and lambda functions timeout problem 如何查看 AWS API Gateway V2 Custom Authorizor 的打印日志? - How to view print logs for AWS API Gateway V2 Custom Authorizor? AWS API 网关 REST API 是否没有设置禁用 CloudFormation 模板中的 execute-api 端点? - Is there no setting for AWS API Gateway REST API to disable execute-api endpoint in CloudFormation template?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM