首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无服务器: httpApi中的请求参数

无服务器: httpApi中的请求参数
EN

Stack Overflow用户
提问于 2020-11-06 00:24:51
回答 2查看 575关注 0票数 0

这是我的serverless.yml部分的样子:

代码语言:javascript
复制
my-function:
      - http:  # <---- http
          method: POST
          path: /my-function/{id}
          request:
            parameters:
              paths: id:true

我想使用AWS HTTP-API。因此,我将http ->改为httpApi,如下所示:

代码语言:javascript
复制
my-function:
      - httpApi:  # <---- now httpApi
          method: POST
          path: /my-function/{id}
          request:
            parameters:
              paths: id:true

但是我得到了这个错误信息:

代码语言:javascript
复制
Serverless: Configuration warning at 'functions['my-function'].events[2].httpApi': unrecognized property 'request'

如何在httpApi节中定义URL参数?

EN

回答 2

Stack Overflow用户

发布于 2021-01-24 09:55:44

其中一个建议是,我使用serverless 4天后才意识到,我需要首先了解Lambda和整个架构。如果你对整个事情都是新手,我会先跳过无服务器框架,然后再回头看看,因为它非常有用。可以回答您的问题:

这是基本的httpApi格式:

代码语言:javascript
复制
functions:
  params:
    name: myLambdaName
    handler: index.handler
    events:
      - httpApi:
          path: /v1/test
          method: get

这是你需要的official documentation

这是serverless.yml文件中所有内容的样子,我添加了一些注释,以便您了解发生了什么:

代码语言:javascript
复制
service: my-express-application

frameworkVersion: "2"

provider:
  name: aws
  stackName: myName # Use a custom name for the CloudFormation stack
  runtime: nodejs12.x
  lambdaHashingVersion: 20201221
  stage: v1 # your default stage, the one lambda and all services define here will use
  region: us-east-1 # <- This is your regeion, make sure it is or change it
  httpApi: # rdefining your existing api gateway
    # id: xxx # id of externally created HTTP API to which endpoints should be attached. This will allow you to use it but this lambda can't modify it
    payload: "2.0" # the latest payload version by aws is 2.0
    name: "v1-my-service" # Use custom name for the API Gateway API, default is ${opt:stage, self:provider.stage, 'dev'}-${self:service} you will only be able to modify it if you created the api using this stack and not referencing it above
    cors: false # Implies default behavior, can be fine tuned with specficic options
  timeout: 10
  logRetentionInDays: 7 # Set the default RetentionInDays for a CloudWatch LogGroup

functions:
  params:
    name: myLambdaName
    handler: index.handler
    events:
      - httpApi:
          path: /v1/test
          method: get
票数 0
EN

Stack Overflow用户

发布于 2021-07-08 00:59:01

我不知道是不是太晚了,但这就是答案

  1. 你不必使用"request..."

handler: bin/function events: - httpApi: path: /function/{id} method: post

代码中的

  1. (本例中为go),只需通过以下方式调用参数即可

id:= request.PathParameters["id"]

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

https://stackoverflow.com/questions/64701242

复制
相关文章

相似问题

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