Home > OS >  How to SAM invoke from outside of the `template` directory with Golang?
How to SAM invoke from outside of the `template` directory with Golang?

Time:01-28

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?

CodePudding user response:

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

  • Related