sam 包正在减小我的模板的大小

sam package is reducing the size of my template

我有一个 SAM 模板,用于构建与 API 网关集成的 4 个 lambda 函数。

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: An AWS Serverless Specification template describing your function.

#To avoide 'stage' being created when deploying the Api gateway.
Globals:
  Api:
    OpenApiVersion: 3.0.1


Resources:
  # api gateway model for all user methods 
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      Name: loadeo_user
      StageName: Development
      Cors: "'*'"

  # integrating lambda with api for loadeo_get_all_user function    
  GetAllUser:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: loadeo_get_all_user
      CodeUri: getAllUser/
      Handler: get_all_user.lambda_handler
      Timeout: 5
      Runtime: python3.8
      Role: loadeo_lambda_execution
      MemorySize: 128
      Events:
        GetAllUser:
          Type: Api
          Properties:
            Path: /get-all-user
            Method: get
            RestApiId:
              Ref: ApiGatewayApi

  # integrating lambda with api for loadeo_get_user_profile function             
  GetUserProfile:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: loadeo_get_user_profile
      CodeUri: getUserProfile/
      Handler: get_user_profile.lambda_handler
      Timeout: 5
      Runtime: python3.8
      Role: loadeo_lambda_execution
      MemorySize: 128
      Events:
        GetAllUser:
          Type: Api
          Properties:
            Path: /get-user-profile
            Method: get
            RestApiId:
              Ref: ApiGatewayApi
#  integrating lambda with api for loadeo_update_user_profile function   
  GetUserProfile:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: loadeo_update_user_profile
      CodeUri: updateUserProfile/
      Handler: update_user_profile.lambda_handler
      Timeout: 5
      Runtime: python3.8
      Role: loadeo_lambda_execution
      MemorySize: 128
      Events:
        GetAllUser:
          Type: Api
          Properties:
            Path: /update_user_profile-user
            Method: patch
            RestApiId:
              Ref: ApiGatewayApi 


#  integrating lambda with api for loadeo_create_user function
  GetUserProfile:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: loadeo_create_user
      CodeUri: createUser/
      Handler: create_all_user.lambda_handler
      Timeout: 5
      Runtime: python3.8
      Role: loadeo_lambda_execution
      MemorySize: 128
      Events:
        GetAllUser:
          Type: Api
          Properties:
            Path: /create-user
            Method: put
            RestApiId:
              Ref: ApiGatewayApi             
              

此后的下一步是打包和部署代码。

我正在使用 aws cloudformation package,因为它与 sam package 类似,我都试过了。

一旦我 运行 命令,模板文件就会减少。 从 100 行到 50 行。当我观察到中间两个函数被省略时。

不完全知道这是什么原因。功能数量有限制吗?或者我遗漏了什么?

two functions are being omitted.

函数被跳过,因为它们具有 GetUserProfile 相同名称。因此,当您拥有三个时,一个会覆盖另一个。您必须重命名它们:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: An AWS Serverless Specification template describing your function.

#To avoide 'stage' being created when deploying the Api gateway.
Globals:
  Api:
    OpenApiVersion: 3.0.1


Resources:
  # api gateway model for all user methods 
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      Name: loadeo_user
      StageName: Development
      Cors: "'*'"

  # integrating lambda with api for loadeo_get_all_user function    
  GetAllUser:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: loadeo_get_all_user
      CodeUri: getAllUser/
      Handler: get_all_user.lambda_handler
      Timeout: 5
      Runtime: python3.8
      Role: loadeo_lambda_execution
      MemorySize: 128
      Events:
        GetAllUser:
          Type: Api
          Properties:
            Path: /get-all-user
            Method: get
            RestApiId:
              Ref: ApiGatewayApi

  # integrating lambda with api for loadeo_get_user_profile function             
  GetUserProfile:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: loadeo_get_user_profile
      CodeUri: getUserProfile/
      Handler: get_user_profile.lambda_handler
      Timeout: 5
      Runtime: python3.8
      Role: loadeo_lambda_execution
      MemorySize: 128
      Events:
        GetAllUser:
          Type: Api
          Properties:
            Path: /get-user-profile
            Method: get
            RestApiId:
              Ref: ApiGatewayApi
#  integrating lambda with api for loadeo_update_user_profile function   
  UpdateUserProfile:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: loadeo_update_user_profile
      CodeUri: updateUserProfile/
      Handler: update_user_profile.lambda_handler
      Timeout: 5
      Runtime: python3.8
      Role: loadeo_lambda_execution
      MemorySize: 128
      Events:
        GetAllUser:
          Type: Api
          Properties:
            Path: /update_user_profile-user
            Method: patch
            RestApiId:
              Ref: ApiGatewayApi 


#  integrating lambda with api for loadeo_create_user function
  CreateUser:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: loadeo_create_user
      CodeUri: createUser/
      Handler: create_all_user.lambda_handler
      Timeout: 5
      Runtime: python3.8
      Role: loadeo_lambda_execution
      MemorySize: 128
      Events:
        GetAllUser:
          Type: Api
          Properties:
            Path: /create-user
            Method: put
            RestApiId:
              Ref: ApiGatewayApi