首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >REST API openapi spec AWS API网关与serverless.com框架的集成

REST API openapi spec AWS API网关与serverless.com框架的集成
EN

Stack Overflow用户
提问于 2020-04-17 14:48:28
回答 1查看 430关注 0票数 1

我正在试用亚马逊网络服务作为提供商的serverless.com。我想用API Gateway和Lambda做一个简单的hello world应用程序,在那里我从openapi规范发布API。

我已经在这个forum post中看到,我需要在serverless.yml文件中将规范声明为资源,但是在这样做的时候,我在执行sls deploy时得到了以下错误:

我想我基本上是正确的,除了在openapi规范文件中,我不知道如何正确地引用我正在创建的API的URI。这是我得到这个错误的原因吗?

代码语言:javascript
复制
  Serverless Error ---------------------------------------

  An error occurred: ApiGatewayRestApi - Errors found during import:
    Unable to put integration on 'GET' for resource at path '/hello': Invalid function ARN or invalid uri (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: ...).

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.16.2
     Framework Version:         1.67.3
     Plugin Version:            3.6.6
     SDK Version:               2.3.0
     Components Version:        2.29.3

我正在尝试我能想到的最简单的例子:

代码语言:javascript
复制
# serverless.yml
service: accounts-api

provider:
  name: aws
  apiName: accounts
  runtime: nodejs12.x
  stage: dev
  region: ap-southeast-2

functions:
  hello:
    handler: functions/handler.hello
    events:
      - http:
           path: /accounts
           method: GET

# The resources attribute will be sent directly to CloudFormation in raw format
resources:
    Resources:
      ApiGatewayRestApi:
        Type: 'AWS::ApiGateway::RestApi'
        Properties:
          Name: ${self:provider.apiName}-${self:provider.stage}
          Body:
            ${file(specs/simple-spec.yml)}
      ApiGatewayDeployment:
        Type: AWS::ApiGateway::Deployment
        Properties:
          RestApiId:
            Ref: ApiGatewayRestApi
          StageName: ${self:provider.stage}

和openapi规范:

代码语言:javascript
复制
openapi: 3.0.0
info:
  version: 1.0.0
  title: Hello API
  description: Returns a hello world message

paths:
  /hello:
    get:
      description: Returns a hello world message              
      responses:
        '200':
          description: Successful response
      security:
      - api_key: []
      x-amazon-apigateway-auth:
        type: none          
      x-amazon-apigateway-integration:
         x-amazon-apigateway-integration:
         type: aws_proxy
         uri: arn:aws:apigateway:ap-southeast-2:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-2:idAccount:function:hello/invocations
         httpMethod: GET
         passthroughBehavior: when_no_templates
         payloadFormatVersion: 1.0
EN

回答 1

Stack Overflow用户

发布于 2020-04-17 15:26:51

在serverless.yml文件中,您在region: ap-southeast-2中创建了lambda,但是在openapi定义(uri: arn:aws:apigateway:ap-northeast-1:lambda...)中,您引用了一个不同的区域:ap-东北-1

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61265620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档