title: issue creating zip file through aws codebuild for nodejs lambda
body: <p>I want to create a zip artifact for my nodejs lambda through aws codebuild process - so that lambda function can use this zip file as source in S3 and we have a deployment "proof" for management with git commit id in codebuild</p>
  
  <p>my file structure in github-repo is </p>
  
  <pre><code>folder1
     - myfile.js
     - otherfile.js
  folder2
     - otherfiles.js
  package.json
  </code></pre>
  
  <p>now for nodejs lambda project I want zip file without the folder in zip (we need that for nodejs project in lambda) so zip should directly contain following files </p>
  
  <pre><code>- myfile.js
  - node_module ==&gt; folder from codebuild via npm install command 
  </code></pre>
  
  <p>issues:</p>
  
  <p>1) output zip in S3 contains in folder i.e       .zip->rootfolder->myfile.js rather than we require        .zip->myfiles.js 
  this is not usable by lambda as for nodejs it should have files in root zip and not inside them (no relative path inside folder) </p>
  
  <p>2) paths - as you can see myfile.js is inside a folder I want to relative path to be omitted - I tried discard path but problem with that is all the node_module files are also in folder rather than in folder as discard path applies to both of them - Can I set discard path only for myfile.js and not for node_module folder ??
  my current yaml file:</p>
  
  <pre><code>artifacts:
    files:
      - folder/myfile.js
      - node_modules/**/*
    discard-paths: yes 
  </code></pre>
  
  <p>It would be great if someone can provide solution to this?</p>
  
  <p>It would be great if solution does not contain changing github-repo folder structure and I want to repeat this for other files too in that repo for creating other lambda functions.</p>
  
  <p>Edit:</p>
  
  <p>I used below yaml file and everything is working fine after @awsnitin answer</p>
  
  <pre><code>version: 0.2
  
  phases:
    build:
      commands:
        - echo Build started on `date`
        - npm install
    post_build:
      commands:
        - echo Running post_build commands
        - mkdir build-output
        - cp -R folder1/myfile.js build-output
        - mkdir -p build-output/node_modules
        - cp -R node_modules/* build-output/node_modules
        - cd build-output/
        - zip -qr build-output.zip ./*
        - mv build-output.zip ../
        - echo Build completed on `date`
  artifacts:
    files:
      - build-output.zip
  </code></pre>