【问题标题】:SAM Lambda event with an explicit API as the event source以显式 API 作为事件源的 SAM Lambda 事件
【发布时间】:2018-03-07 22:28:17
【问题描述】:

我正在尝试在我的 SAM 模板中的 lambda 函数上设置一个事件,但我希望事件源是一个明确的 API 端点。

文档显示了一个使用隐式 API 作为事件源的事件:

GetFunction:
  Type: AWS::Serverless::Function
  Properties:
    Handler: index.get
    Runtime: nodejs6.10
    CodeUri: s3://bucket/api_backend.zip
    Policies: AmazonDynamoDBReadOnlyAccess
    Environment:
      Variables:
        TABLE_NAME: !Ref Table
    Events:
      GetResource:
        Type: Api
        Properties:
          Path: /resource/{resourceId}
          Method: get

这将是明确的 API 定义:

Resources:
  MyApi: 
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
      DefinitionUri: swagger.yml

如何将事件源显式设置为 MyApi?

【问题讨论】:

    标签: amazon-web-services aws-api-gateway api-gateway aws-sam


    【解决方案1】:

    我需要像这样在事件定义下添加RestApiId:

    Events:
        GetResource:
          Type: Api
          Properties:
            RestApiId: !Ref MyApi
            Path: /resource/{resourceId}
            Method: get
    

    【讨论】:

      猜你喜欢
      • 2019-01-22
      • 2021-10-04
      • 2021-11-17
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多