为什么 AWS HttpApi 不需要 Cloudformation Resource 声明?

问题描述

我正在与 AWS 官方 tutorial 合作研究如何创建 RESTful CRUD API,并且 YML 模板不包含 AWS Class 声明。

AWS::Serverless::Api

但是,在另一个使用 RestApitutorial example 上,可以在 YML 模板中找到 API 资源的声明。

AWstemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  Example template for an HTTP API that creates,updates,and deletes items in DynamoDB
  
Globals:
  Function:
    Timeout: 10

Resources:
  DDBHandlerFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: dynamo-handler/
      Handler: app.handler
      Runtime: nodejs12.x
      Policies:
        - DynamoDBCrudPolicy:
            TableName: !Ref ItemsTable
      Events:
        GetAllItems:
          Type: HttpApi
          Properties:
            Path: /items
            Method: GET
        GetAnItem:
          Type: HttpApi
          Properties:
            Path: /items/{id}
            Method: GET
        DeleteAnItem:
          Type: HttpApi
          Properties:
            Path: /items/{id}
            Method: DELETE
        CreateOrUpdateItem:
          Type: HttpApi
          Properties:
            Path: /items
            Method: PUT

  ItemsTable:
    Type: AWS::Serverless::SimpleTable
    Properties:
      PrimaryKey:
        Name: id
        Type: String
      TableName: http-crud-tutorial-items

Outputs:
  ApiEndpoint:
    Description: "The invoke URL for our HTTP API"
    Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/items"
  Function:
    Description: "DynamoDB handler function ARN"
    Value: !GetAtt DDBHandlerFunction.Arn

这是为什么?这是设计使然吗,因为 HttpApi 被认为是“轻量级”的?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)