小编Chr*_*ris的帖子

使用 SAM 将 lambda 集成添加到 HttpApi 路由

我目前正在尝试AWS::Serverless::HttpApi与一群AWS::Serverless::Function人进行整合。目标是在 SAM 模板中定义这些资源,并使用 swagger 文件定义实际的 API。

我的 SAM 模板定义如下:


Resources:
  apiPing:
    Type: AWS::Serverless::Function
    Properties:
      Description: 'Ping'
      CodeUri: ../bin/cmd-api-ping.zip
      Handler: cmd-api-ping
      Runtime: go1.x
      Role:
        Fn::GetAtt: apiLambdaRole.Arn
      Events:
        PingEvent:
          Type: HttpApi
          Properties:
            ApiId: !Ref api
            Path: /ping
            Method: post
  api:
    Type: AWS::Serverless::HttpApi
    Properties:
      StageName: prod
      DefinitionBody:
        Fn::Transform:
          Name: AWS::Include
          Parameters:
            Location: swagger.yaml
      AccessLogSettings:
        DestinationArn: !GetAtt accessLogs.Arn
        Format: $context.requestId
Run Code Online (Sandbox Code Playgroud)

还有我的招摇文件:

openapi: 3.0.1
info:
  title: 'API'
  version: 2019-10-13

paths:
  /ping:
    post:
      summary: 'invoke ping'
      operationId: 'apiPing'
      requestBody:
        content:
          application/json:
            schema: …
Run Code Online (Sandbox Code Playgroud)

aws-cloudformation aws-sam

5
推荐指数
1
解决办法
1236
查看次数

标签 统计

aws-cloudformation ×1

aws-sam ×1