如何使用 Golang 從 `template` 目錄外部呼叫 SAM?
php小編柚子將為您介紹如何使用Golang從`template`目錄外部呼叫SAM。 SAM(Serverless Application Model)是一種用於定義和部署無伺服器應用程式的開發框架,而Golang則是一種高效且易於使用的程式語言。在開發過程中,我們可能需要從外部目錄呼叫SAM模板,本文將詳細介紹此過程。透過以下步驟,您將能夠輕鬆在Golang中使用外部SAM範本。
問題內容
我有一個多模組項目,其中一個模組用於執行整合測試,而另一個模組則包含我的應用程式(待測試)。我想從 sam 模板目錄外部運行 build
和 invoke
。
使用指令 sam build -ttests/helloworld/template.yaml
執行階段建立工作正常,如下所示
~/w/r/sommelier (feature-integrationtests|✔) $ sam build -t tests/helloworld/template.yaml building codeuri: /users/kuldeep/work/repos/sommelier/lambdas/import-recommendations runtime: provided.al2 metadata: {'buildmethod': 'go1.x'} architecture: arm64 functions: helloworldfunction running gomodulesbuilder:build build succeeded built artifacts : .aws-sam/build built template : .aws-sam/build/template.yaml commands you can use next ========================= [*] validate sam template: sam validate [*] invoke function: sam local invoke [*] test function in the cloud: sam sync --stack-name {{stack-name}} --watch [*] deploy: sam deploy --guided
但是當我嘗試呼叫時,它失敗如下
~/W/r/sommelier (feature-integrationTests|✔) $ sam local invoke -t tests/helloworld/template.yaml Invoking bootstrap (provided.al2) Skip pulling image and use local one: public.ecr.aws/sam/emulation-provided.al2:rapid-1.70.0-arm64. Mounting /Users/kuldeep/Work/repos/sommelier/lambdas/import-recommendations as /var/task:ro,delegated inside runtime container START RequestId: 53716d16-562c-42f1-bad7-b415e27004b3 Version: $LATEST 24 Jan 2023 09:56:03,133 [ERROR] (rapid) Init failed error=fork/exec /var/task/bootstrap: no such file or directory InvokeID= Function 'HelloWorldFunction' timed out after 5 seconds END RequestId: 5eeafe42-303b-40b4-bf96-d74809bb8636 REPORT RequestId: 5eeafe42-303b-40b4-bf96-d74809bb8636 Init Duration: 0.13 ms Duration: 5000.00 ms Billed Duration: 5000 ms Memory Size: 128 MB Max Memory Used: 128 MB No response from invoke container for HelloWorldFunction
我應該怎麼做才能達成這個目標?
解決方法
想通了。基本上, sam build -t ......
在目前工作目錄中建置並產生工件。要運行已建置的內容,我們不需要指定模板位置,而是直接執行 sam local invoke
以上是如何使用 Golang 從 `template` 目錄外部呼叫 SAM?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

OpenSSL,作為廣泛應用於安全通信的開源庫,提供了加密算法、密鑰和證書管理等功能。然而,其歷史版本中存在一些已知安全漏洞,其中一些危害極大。本文將重點介紹Debian系統中OpenSSL的常見漏洞及應對措施。 DebianOpenSSL已知漏洞:OpenSSL曾出現過多個嚴重漏洞,例如:心臟出血漏洞(CVE-2014-0160):該漏洞影響OpenSSL1.0.1至1.0.1f以及1.0.2至1.0.2beta版本。攻擊者可利用此漏洞未經授權讀取服務器上的敏感信息,包括加密密鑰等。

後端學習路徑:從前端轉型到後端的探索之旅作為一名從前端開發轉型的後端初學者,你已經有了nodejs的基礎,...

在BeegoORM框架下,如何指定模型關聯的數據庫?許多Beego項目需要同時操作多個數據庫。當使用Beego...

Go語言中用於浮點數運算的庫介紹在Go語言(也稱為Golang)中,進行浮點數的加減乘除運算時,如何確保精度是�...

Go爬蟲Colly中的Queue線程問題探討在使用Go語言的Colly爬蟲庫時,開發者常常會遇到關於線程和請求隊列的問題。 �...

GoLand中自定義結構體標籤不顯示怎麼辦?在使用GoLand進行Go語言開發時,很多開發者會遇到自定義結構體標籤在�...

Go語言中字符串打印的區別:使用Println與string()函數的效果差異在Go...

Go語言中使用RedisStream實現消息隊列時類型轉換問題在使用Go語言與Redis...
