我正在试用亚马逊网络服务作为提供商的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发布于 2020-04-17 15:26:51
在serverless.yml文件中,您在region: ap-southeast-2中创建了lambda,但是在openapi定义(uri: arn:aws:apigateway:ap-northeast-1:lambda...)中,您引用了一个不同的区域:ap-东北-1
https://stackoverflow.com/questions/61265620
复制相似问题