英文:
How to SAM invoke from outside of the `template` directory with Golang?
问题
我有一个多模块项目,其中一个模块用于运行集成测试,而另一个模块包含我的应用程序(需要进行测试)。我希望能够从 SAM 模板目录外部运行 build
和 invoke
。
当我使用以下命令运行构建时,构建工作正常:
~/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
构建成功
构建的构件:.aws-sam/build
构建的模板:.aws-sam/build/template.yaml
下一步可以使用的命令
=========================
[*] 验证 SAM 模板:sam validate
[*] 调用函数:sam local invoke
[*] 在云中测试函数:sam sync --stack-name {{stack-name}} --watch
[*] 部署:sam deploy --guided
但是,当我尝试调用时,出现以下错误:
~/W/r/sommelier (feature-integrationTests|✔) $ sam local invoke -t tests/helloworld/template.yaml
正在调用 bootstrap (provided.al2)
跳过拉取镜像并使用本地镜像:public.ecr.aws/sam/emulation-provided.al2:rapid-1.70.0-arm64。
将 /Users/kuldeep/Work/repos/sommelier/lambdas/import-recommendations 挂载为 /var/task:ro,delegated 在运行时容器内部
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=
函数 'HelloWorldFunction' 在 5 秒后超时
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
HelloWorldFunction 的调用容器没有响应
我应该怎么做才能实现这个?
英文:
I am having a multi-module project where one of my module is for running integration tests, while another module has my application(to be tested). I want to run build
and invoke
from outside of SAM template directory.
Build worked fine when ran with the command sam build -t tests/helloworld/template.yaml
as shown below
~/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
But when I try to invoke, it fails as following
~/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
What should I do to achieve this?
答案1
得分: 1
我明白了。基本上,sam build -t ......
命令会在当前工作目录中构建并生成构件。而要运行已构建的内容,我们无需指定模板位置,直接使用sam local invoke
命令即可。
英文:
Figured it out. Basically, sam build -t ......
builds and generate artefacts in the present working directory. And to run what has been build we need not specify the template location but directly run like sam local invoke
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论