Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility for to exclude not needed files from deployment package #308

Closed
Jacksotnik opened this issue Feb 19, 2018 · 9 comments
Closed

Comments

@Jacksotnik
Copy link

Jacksotnik commented Feb 19, 2018

Hello here is my project structure:

-AppName
    -Common
        -common.js //Global module which i'm using in all functions
    -Func1
        -index.js
    -Func2
        -index.js
    -template.yaml

And here is template.yaml content:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
      Func1:
        Type: 'AWS::Serverless::Function'
        Properties:
          Handler: Func1/index.handler
          Runtime: nodejs6.10
          MemorySize: 512
          Timeout: 10
      Func2:
        Type: 'AWS::Serverless::Function'
        Properties:
          Handler: Func2/index.handler
          Runtime: nodejs6.10
          MemorySize: 512
          Timeout: 10

When i deploy for example Func2, result package contain all folders inside application, instead only Func2. Is it possible to configure through yaml file, what files will included in result package?
For example if i deploy Func2 i want to see in package next:

-Common
    -common.js
-Func2
    -index.js
@brettstack
Copy link
Contributor

The local package logic actually exists in the AWS CLI (aws cloudformation package). You can open a ticket there, but they're unlikely to be able to help. Your Func2 needs to know about Common, so they must both exist in the ZIP. If you really want lightweight bundles, try something like WebPack for Node.js

@talawahtech
Copy link

FYI for anyone that comes across this. The new sam build command uses npm to package up the build folder (for nodejs projects), so you can use .npmignore to tell it which files should be excluded from the build.

@y15e
Copy link

y15e commented May 1, 2019

In addition to the above .npmignore tip, file property of package.json also works with sam build. .npmignore is a blacklist, files property is a whitelist.

https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package

If, given the structure of your project, you find .npmignore to be a maintenance headache, you might instead try populating the files property of package.json, which is an array of file or directory names that should be included in your package. Sometimes a whitelist is easier to manage than a blacklist.

@aalaap
Copy link

aalaap commented Nov 26, 2020

@talawahtech I tried this, but I can still see the files inside the ./aws-sam/build folder after sam build has finished. Does this not work locally or am I missing something?

@piersf
Copy link

piersf commented Apr 22, 2021

Is this possible to do? Is there a flag to pass with files that one can exclude during build and package?

@Yop-La
Copy link

Yop-La commented Feb 4, 2022

+1 none of the proposed solutions work for a project other than node-js. This feature would be very useful.

@Yop-La
Copy link

Yop-La commented Feb 4, 2022

Quick workaround with a .samignore file and a clean-sam-build.sh

.samignore

.DS_Store
.env
.flaskenv
*.pyc
*.pyo
env
venv
.venv
env*
dist

clean-sam-build.sh

#!/bin/bash
echo 'cleaning'

while read p; do
  echo 'Deleting ' $p
  rm -rf .aws-sam/build/ExplicitAlgoFunction/$p
done < .samignore

sam build && sh clean-sam-build.sh

@alexongh
Copy link

@talawahtech I tried this, but I can still see the files inside the ./aws-sam/build folder after sam build has finished. Does this not work locally or am I missing something?

Same. Seems no longer to be working

@SHi-ON
Copy link

SHi-ON commented Jun 4, 2023

One other approach –for all projects– instead of ignoring files, could be including a soft-linked file of only other files or directories that you want to be included, in your CodeUri.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants