jhu*_*tas 2 aws-cloudformation aws-lambda aws-api-gateway aws-serverless
我正在尝试部署lambda函数和API网关。我使用AWS CLI创建一个.net核心Web API项目。在AWS Web控制台上仅部署功能并手动创建API网关和资源即可。
如果我确实将API网关包括在模板中,则在通过Web控制台或CLI进行SAM包部署后,出现以下错误:
“没有为方法定义任何集成(服务:AmazonApiGateway;状态代码:400;错误代码:BadRequestException;请求ID:...。)”
这里有什么问题或遗漏吗?
SAM软件包命令:
sam package --template-file sam-profile.yaml --output-template-file serverless-output.yaml --s3-bucket testapp-fewtfvdy-lambda-deployments
Run Code Online (Sandbox Code Playgroud)
SAM模板:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
ProfileFunction:
Type: AWS::Serverless::Function
Properties:
Handler: testapp.Profile.NetCoreVS::testapp.Profile.NetCoreVS.LambdaEntryPoint::FunctionHandlerAsync
Runtime: dotnetcore2.0
MemorySize : 128
Timeout : 5
CodeUri: bin/Release/netcoreapp2.0/publish
Events:
ProfileAny:
Type: Api
Properties:
RestApiId: !Ref ProfileApiGateway
Path: /profile/v1
Method: GET
ProfileApiGateway:
DependsOn: ProfileFunction
Type: 'AWS::Serverless::Api'
Properties:
StageName: Prod
DefinitionUri: './swagger.yaml'
Run Code Online (Sandbox Code Playgroud)
swagger.yaml:
---
swagger: '2.0'
info:
version: v1
title: ProfileAPI
paths:
"/profile/v1":
get:
tags:
- Values
operationId: ProfileV1Get
consumes: []
produces:
- text/plain
- application/json
- text/json
parameters: []
responses:
'200':
description: Success
schema:
type: array
items:
type: string
definitions: {}
Run Code Online (Sandbox Code Playgroud)
[Route("profile/v1")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2","value_new3" };
}
}
Run Code Online (Sandbox Code Playgroud)
您的挥霍定义丢失了x-amazon-apigateway-integration。
这应该为您提供该集成层:
---
swagger: '2.0'
info:
version: v1
title: ProfileAPI
paths:
"/profile/v1":
get:
tags:
- Values
operationId: ProfileV1Get
consumes: []
produces:
- text/plain
- application/json
- text/json
parameters: []
responses:
'200':
description: Success
schema:
type: array
items:
type: string
x-amazon-apigateway-integration:
httpMethod: post
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ProfileFunction.Arn}/invocations
definitions: {}
Run Code Online (Sandbox Code Playgroud)
请注意,httpMethod x-amazon-apigateway-integration始终为POST,因为API网关始终向Lambda发出POST请求,无论您的API路由使用哪种方法。
| 归档时间: |
|
| 查看次数: |
1815 次 |
| 最近记录: |