亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

擁有多個 main.go 文件以部署基于 AWS Lambda 的應用程序

擁有多個 main.go 文件以部署基于 AWS Lambda 的應用程序

Go
倚天杖 2023-06-19 14:05:30
我有以下復雜的結構:utils:    - utils.gofunction1:    pkg1_specific_to_fn1:        -pkg1_specific_to_fn1.go    pkg2_specific_to_fn1:        -pkg2_specific_to_fn1.go    main.gofunction2:    pkg1_specific_to_fn1:        -pkg1_specific_to_fn2.go    pkg2_specific_to_fn1:        -pkg2_specific_to_fn2.go    main.gofunction3:    pkg1_specific_to_fn1:        -pkg1_specific_to_fn3.go    pkg2_specific_to_fn1:        -pkg2_specific_to_fn3.go    main.go如何在 GoLang 中為所有這些函數創建 .YML 部署文件?如果所有這些函數都有自己的 main,會有什么問題嗎?我是 GoLang 的新手,但據我所知,包只能包含一個 main.go 文件,而在 YML 文件中,handler我必須為屬性指定可執行文件bin。這是我的想法:service: myServiceprovider:  name: aws  runtime: go1.xfunctions:  function1:    handler: bin/function1/main    description: ..    events: ..  function2:    handler: bin/function2/main    events: ..  function3:    handler: bin/function3/main因為我有多個代表多個 Lambda 函數的包,所以我應該可以在每個包中包含 main.go,對嗎?如果不是那么正確的方法是什么?另外,如果這沒問題,我如何main為每個函數指定正確的二進制文件,這真的是用 GoLang 部署多個 lambda 的慣例嗎?注意: 在每個 main.go 中都有一個對應的函數 Handler。
查看完整描述

1 回答

?
翻翻過去那場雪

TA貢獻2065條經驗 獲得超14個贊

lambda 函數的部署歸結為包/模塊組織和自動化部署工具。第一個看起來像是在您的問題中解決了共享代碼被放置到 util 并且每個 lambda 都有一個單獨的包。在問題中,不清楚使用的是什么部署方法。有多種方法可以部署 lambda

  • 命令行界面

  • AWS 無服務器應用程序模型

  • Endly - 自動化和 e2e 運行器

  • 地貌

雖然我一直是 e2e 和自動化的倡導者,但針對各種事件的最終運行器多 lambda 部署工作流程可能如下所示


init:

? fn1ZipLocation: somepath1.zip

? fn2ZipLocation: somepath2.zip

? fnXZipLocation: somepathX.zip


pipeline:


? build:

? ? fn1:

? ? ? action: exec:run

? ? ? target: $target

? ? ? sleepTimeMs: 1500

? ? ? errors:

? ? ? ? - ERROR

? ? ? commands:

? ? ? ? - cd ${appPath}aeroagg/app

? ? ? ? - unset GOPATH

? ? ? ? - export GOOS=linux

? ? ? ? - export GOARCH=amd64

? ? ? ? - go build -o function1

? ? ? ? - zip -j somepath1.zip function1


? ...


? deployFunctions:

? ? fn1:

? ? ? action: aws/lambda:deploy

? ? ? credentials: aws-e2e

? ? ? functionname: fn1

? ? ? runtime:? go1.x

? ? ? handler: main

? ? ? code:

? ? ? ? zipfile: $LoadBinary(${fn1ZipLocation})

? ? ? rolename: lambda-fn1-executor

? ? ? define:

? ? ? ? - policyname: xxx-resource-fn1-role

? ? ? ? ? policydocument: $Cat('${privilegePolicy}')

? ? ? attach:

? ? ? ? - policyarn: arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

? ? ? triggers:

? ? ? ? - source: somequeue

? ? ? ? ? type: sqs

? ? ? ? ? enabled: true

? ? ? ? ? batchSize: 20000

? ? fn2:

? ? ? action: aws/lambda:deploy

? ? ? credentials: aws-e2e

? ? ? functionname: fn2

? ? ? runtime:? go1.x

? ? ? handler: main

? ? ? code:

? ? ? ? zipfile: $LoadBinary(${fn2ZipLocation})

? ? ? rolename: lambda-fn2-executor

? ? ? define:

? ? ? ? - policyname: xxx-resource-fn2-role

? ? ? ? ? policydocument: $Cat('${privilegePolicy}')

? ? ? attach:

? ? ? ? - policyarn: arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole


? ? ? notification:

? ? ? ? action: aws/s3:setupBucketNotification

? ? ? ? bucket: someBucket

? ? ? ? lambdaFunctionConfigurations:

? ? ? ? ? - functionName: fn2

? ? ? ? ? ? id: ObjectCreatedEvents

? ? ? ? ? ? events:

? ? ? ? ? ? ? - s3:ObjectCreated:*

? ? ? ? ? ? filter:

? ? ? ? ? ? ? prefix:

? ? ? ? ? ? ? ? - folderXXX

? ? ? ? ? ? ? suffix:

? ? ? ? ? ? ? ? - .csv


? ? ? ...

? ? fnX:

? ? ? action: aws/lambda:deploy

? ? ? ? functionname: fnX

? ? ? ? runtime:? go1.x

? ? ? ? handler: main

? ? ? ? timeout: 360

? ? ? ? vpcMatcher:

? ? ? ? ? instance:

? ? ? ? ? ? name: instanceWithVPC


? ? ? ? environment:

? ? ? ? ? variables:

? ? ? ? ? ? CONFIG: $AsString($config)

? ? ? ? code:

? ? ? ? ? zipfile: $LoadBinary(${fn2ZipLocation})

? ? ? ? rolename: lambda-fn3-executor

? ? ? ? define:

? ? ? ? ? - policyname: lambda-sns-execution-role

? ? ? ? ? ? policydocument: $Cat('${privilegePolicy}')

? ? ? ? attach:

? ? ? ? ? - policyarn: arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

? ? ? ? ? - policyarn: arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole

? ? ? setupSubscription:

? ? ? ? action: aws/sns:setupSubscription

? ? ? ? protocol: lambda

? ? ? ? endpoint: fnX

? ? ? ? topic: someTopic


? ? deployGatewayAPI:

? ? ? redeploy: true

? ? ? action: aws/apigateway:setupRestAPI

? ? ? '@name': myAPIName

? ? ? resources:

? ? ? ? - path: /

? ? ? ? ? methods:

? ? ? ? ? ? - httpMethod: GET

? ? ? ? ? ? ? functionname: fn3

? ? ? ? - path: /{proxy+}

? ? ? ? ? methods:

? ? ? ? ? ? - httpMethod: GET

? ? ? ? ? ? ? functionname: fn4

? ? ? ? - path: /v1/api/fn4

? ? ? ? ? methods:

? ? ? ? ? ? - httpMethod: GET

? ? ? ? ? ? ? functionname: fn5

最后,您可以使用 lambda e2e 實際測試示例檢查?無服務器 e2e。



查看完整回答
反對 回復 2023-06-19
  • 1 回答
  • 0 關注
  • 175 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號