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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

OpenSSL, as an open source library widely used in secure communications, provides encryption algorithms, keys and certificate management functions. However, there are some known security vulnerabilities in its historical version, some of which are extremely harmful. This article will focus on common vulnerabilities and response measures for OpenSSL in Debian systems. DebianOpenSSL known vulnerabilities: OpenSSL has experienced several serious vulnerabilities, such as: Heart Bleeding Vulnerability (CVE-2014-0160): This vulnerability affects OpenSSL 1.0.1 to 1.0.1f and 1.0.2 to 1.0.2 beta versions. An attacker can use this vulnerability to unauthorized read sensitive information on the server, including encryption keys, etc.

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

Backend learning path: The exploration journey from front-end to back-end As a back-end beginner who transforms from front-end development, you already have the foundation of nodejs,...

The difference between string printing in Go language: The difference in the effect of using Println and string() functions is in Go...

This article introduces a variety of methods and tools to monitor PostgreSQL databases under the Debian system, helping you to fully grasp database performance monitoring. 1. Use PostgreSQL to build-in monitoring view PostgreSQL itself provides multiple views for monitoring database activities: pg_stat_activity: displays database activities in real time, including connections, queries, transactions and other information. pg_stat_replication: Monitors replication status, especially suitable for stream replication clusters. pg_stat_database: Provides database statistics, such as database size, transaction commit/rollback times and other key indicators. 2. Use log analysis tool pgBadg

Under the BeegoORM framework, how to specify the database associated with the model? Many Beego projects require multiple databases to be operated simultaneously. When using Beego...

The problem of using RedisStream to implement message queues in Go language is using Go language and Redis...
