萨姆包正在减少我的模板的大小 [英] sam package is reducing the size of my template
问题描述
我有一个SAM模板,用于构建与API网关集成的4个lambda函数.
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.
我正在使用 aws cloudformation软件包
,因为它与 sam软件包
类似,并且我都尝试过.
I am using aws cloudformation package
as it is similar to sam package
and I have tried both.
一旦我运行命令,模板文件就会减少.从100行到50行.当我观察到中间的两个功能被省略时.
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?
推荐答案
两个功能被省略.
two functions are being omitted.
该功能被跳过,因为它们具有 GetUserProfile 的相同名称.因此,当您拥有三个时,一个将覆盖另一个.您必须重命名它们:
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
这篇关于萨姆包正在减少我的模板的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!