gpt4 book ai didi

aws-cloudformation - REST API openapi 规范 AWS API Gateway 与 serverless.com 框架集成

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

我正在试用由 AWS 作为提供商的 serverless.com。我想使用 API Gateway 和 Lambda 制作一个简单的 hello world 应用程序,在其中我根据 openapi 规范发布 API。

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

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

  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

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

# 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 规范:

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

最佳答案

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

关于aws-cloudformation - REST API openapi 规范 AWS API Gateway 与 serverless.com 框架集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61265620/

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