sam package is reducing the size of my template

余生颓废 提交于 2021-02-10 14:36:42

问题


I have a SAM template that I am using to building 4 lambda functions integrated with API gateways.

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             
              

the next step after this to package and deploy the code.

I am using aws cloudformation package as it is similar to sam package and I have tried both.

As soon as I run the command the template file gets reduced. from 100 lines to 50 lines. when I observe the middle two functions are being omitted.

don't exactly know the reason for this. Is there any limit on the number of functions? or I am missing anything?


回答1:


two functions are being omitted.

The functions are skipped because they have same name of GetUserProfile. So one overwrites the other as you have three of them. You have to rename them:

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 


来源:https://stackoverflow.com/questions/66101560/sam-package-is-reducing-the-size-of-my-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!