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
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 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 solution to this?
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.
Edit:
I used below yaml file and everything is working fine after @awsnitin answer
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
build-output
folder will be put inside the root folder of the S3. Anyway to extract the content of thebuild-output
folder so the files will be in the root? Addingdiscard-paths
will just remove all the sub-folders paths. – Isaacisaacs