Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
Custom build step for SAM CLI

When using the AWS SAM CLI to build a serverless application, it located dependencies magically and installs them all as the "build" step. For example, using a NodeJS application:

$> sam build
Building resource 'HelloWorldFunction'
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrc
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc

Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided

$>

Looking at the official documentation they're happy to simply treat it like magic, saying that it:

iterates through the functions in your application, looks for a manifest file (such as requirements.txt) that contains the dependencies, and automatically creates deployment artifacts that you can deploy to Lambda

But what if I have a dependency beyond just those specified in the manifest file? What if my code depends on a compiled binary file, or a static data file?

I would like to add additional build steps so that when I run sam build it compiles these files or copies them appropriately. Is there any way to do this?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

sam build is running npm install. So if you insert your own script into a step such as preinstall in package.json, sam build will also execute that step.

package.json

{
  ...
  "preinstall": "cp -r ../../../common ./"
  ...
}

The above preinstall script is a hack that embeds the common directory in the root folder of the sam inited project in the zip of each lambda handler so that it can be referenced from each.

You should also create a symbolic link in the local lambda handler directory, like ln -s ../common ./common, so that local and lambda work with the same code.

over 4 years ago · Santiago Trujillo Relatório

0

You will need to wrap this command into another custom command and add the steps you need to it.

You can create a make file with multiple targets that satisfy your requirements.

I haven't used sam build before, I usually have a make target for that purpose.

you can give it a try with this bootstrap template here https://github.com/healthbridgeltd/nodejs-sam-bootstrap which is more efficient than using sam build.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda