我有一個解決方案,但在那方面,我必須為每個 lambda 制作一個單獨的 deply.yml,(就像如果有 10 個 lambda,那么我必須為每個 lambda 制作 10 個 deploy.yml)。我想知道是否可以使用單個 deploy.yml 完成這項作業(我也嘗試過無服務器,但沒有奏效)。
uj5u.com熱心網友回復:
在無服務器中,您可以使用單個 serverless.yaml 實作如下
service: my-service
package:
individually: true
patterns:
- '!src/excluded-by-default-for-all-functions.json'
functions:
hello:
handler: handler.hello
package:
# We're including this file so it will be in the final package of this function only
patterns:
- function1/path/somefile.json #some path for function1
- excluded-by-default.json # you can add ignored file in this function alone
world:
handler: handler.world
package:
patterns:
- '!some-file.js' #Not including this file
- 'function2/path/another-file.json' #Including this file
- '!path123/**' #Don't include any file in this path
uj5u.com熱心網友回復:
您可以為此使用AWS SAM。你會有一個template.yml這樣的檔案:
Transform: AWS::Serverless-2016-10-31
Parameters:
Function1Hash:
Type: String
Function2Hash:
Type: String
Resources:
Function1:
Type: AWS::Serverless::Function
Properties:
CodeUri: path/to/my/code
Role: !GetAtt MyRole.Arn
Runtime: myruntime
Handler: lambda_function.handler
AutoPublishCodeSha256: !Ref Function1Hash
Function2:
Type: AWS::Serverless::Function
Properties:
CodeUri: path/to/my/code
Role: !GetAtt MyRole.Arn
Runtime: myruntime
Handler: lambda_function.handler
AutoPublishCodeSha256: !Ref Function2Hash
您為每個 lambda 生成一個散列。這樣,如果 lambda 代碼更改,哈希值也會更改。然后將這些哈希值作為引數注入模板,只有帶有新代碼的 lambda 才會更新,由AutoPublishCodeSha256屬性保證。在你的deploy.yml(未經測驗)中是這樣的:
hash_func_1=$(md5sum lambda1.py | awk '{print $1}')
hash_func_2=$(md5sum lambda2.py | awk '{print $1}')
sam deploy --stack-name my-lambdas -t template.yml --parameter-overrides Function1=$hash_func_1 Function2=$hash_func_2
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/378139.html
標籤:混帐 亚马逊网络服务 aws-lambda 工作流程
上一篇:為什么master分支在`commit`更改之前也會更改
下一篇:Git拉取指定分支沒有任何更改?
