How to call SAM from outside the `template` directory using Golang?
php editor Youzi will introduce to you how to use Golang to call SAM from outside the `template` directory. SAM (Serverless Application Model) is a development framework for defining and deploying serverless applications, and Golang is an efficient and easy-to-use programming language. During the development process, we may need to call the SAM template from an external directory. This article will describe this process in detail. With the following steps, you will be able to use external SAM templates in Golang easily.
Question content
I have a multi-module project where one module is used to run integration tests and another module contains my application (to be tested). I want to run build
and invoke
from outside the sam template directory.
Use the command sam build -ttests/helloworld/template.yaml
The runtime build works fine 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 call it fails as follows
~/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 goal?
Solution
I figured it out. Basically, sam build -t ...
builds and generates artifacts in the current working directory. To run the built content we don't need to specify the template location but directly run sam local invoke
The above is the detailed content of How to call SAM from outside the `template` directory using Golang?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article explains Go's package import mechanisms: named imports (e.g., import "fmt") and blank imports (e.g., import _ "fmt"). Named imports make package contents accessible, while blank imports only execute t

This article details efficient conversion of MySQL query results into Go struct slices. It emphasizes using database/sql's Scan method for optimal performance, avoiding manual parsing. Best practices for struct field mapping using db tags and robus

This article explains Beego's NewFlash() function for inter-page data transfer in web applications. It focuses on using NewFlash() to display temporary messages (success, error, warning) between controllers, leveraging the session mechanism. Limita

This article explores Go's custom type constraints for generics. It details how interfaces define minimum type requirements for generic functions, improving type safety and code reusability. The article also discusses limitations and best practices

This article demonstrates creating mocks and stubs in Go for unit testing. It emphasizes using interfaces, provides examples of mock implementations, and discusses best practices like keeping mocks focused and using assertion libraries. The articl

This article details efficient file writing in Go, comparing os.WriteFile (suitable for small files) with os.OpenFile and buffered writes (optimal for large files). It emphasizes robust error handling, using defer, and checking for specific errors.

The article discusses writing unit tests in Go, covering best practices, mocking techniques, and tools for efficient test management.

This article explores using tracing tools to analyze Go application execution flow. It discusses manual and automatic instrumentation techniques, comparing tools like Jaeger, Zipkin, and OpenTelemetry, and highlighting effective data visualization
