Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)
edited by

I want to create a zip artefact for my nodejs lambda through aws codebuild process - so that lambda function can use this zip file as a source in S3 and we have a deployment "proof" for management with git commit id in codebuild 

my file structure in github-repo is

folder1

   - myfile.js

   - otherfile.js

folder2

   - otherfiles.js

package.json

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

- myfile.js

- node_module ==> folder from codebuild via npm install command 

issues:

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) 

2) paths - as you can see myfile.js is inside a folder I want to relative path to be omitted - I tried to 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: 

artifacts:

  files:

    - folder/myfile.js

    - node_modules/**/*

  discard-paths: yes 

It would be great if someone can provide a solution to this? 

It would be great if the 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.

1 Answer

0 votes
by (44.4k points)

Copy the needed files to a new folder as the part of your build (buildspec.yml) and specify it in artifacts section. This is a sample:

post_build:

    commands:

      - mkdir build-output

      - cp -R folder/myfile.js node_modules/ build-output

artifacts:

  files:

    - build-output/**/*

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...