外部调用 SAM:使用 Golang 从 `template` 目录调用 SAM 的方法详解
时间:2024-02-06
浏览:429
作者:佚名
目前golang学习网上已经有很多关于Golang的文章了,自己在初次阅读这些文章中,也见识到了很多学习思路;那么本文《外部调用 SAM:使用 Golang 从 `template` 目录调用 SAM 的方法详解》,也希望能帮助到大家,如果阅读完后真的对你学习Golang有帮助,欢迎动动手指,评论留言并分享~
问题内容
我有一个多模块项目,其中一个模块用于运行集成测试,而另一个模块则包含我的应用程序(待测试)。我想从 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学习网!更多关于Golang的相关知识,也可关注golang学习网公众号。
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.29
11.29
11.29
11.29
11.29
11.29
热门专题
