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

问题描述

我有一个 SAM 模板,用于构建 4 个与 API 网关集成的 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 行。当我观察到中间的两个函数被省略时。

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

解决方法

省略了两个函数。

这些函数被跳过,因为它们具有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