通过aws codebuild为nodejs lambda创buildzip文件

我想通过aws codebuild过程为我的nodejs lambda创build一个zip工件 – 这样lambda函数可以在S3中使用这个zip文件作为源代码,并且我们有一个部署“certificate”,用于在codebuild中使用git commit id进行pipe理

我在github-repo中的文件结构是

folder1 - myfile.js - otherfile.js folder2 - otherfiles.js package.json 

现在为nodejs lambda项目我想zip文件没有zip文件夹(我们需要的lambda nodejs项目),所以zip应该直接包含以下文件

 - myfile.js - node_module ==> folder from codebuild via npm install command 

问题:

1)在S3输出zip包含在文件夹即.zip-> rootfolder-> myfile.js,而不是我们要求的.zip-> myfiles.js这是不可用的lambda作为nodejs它应该有文件在根zip和不在里面他们(文件夹内没有相对path)

2)path – 你可以看到myfile.js是在一个文件夹我想相对path被省略 – 我试图放弃path,但问题是所有的node_module文件也在文件夹而不是在文件夹作为丢弃path适用于他们两个 – 我可以设置丢弃path只为myfile.js而不是为node_module文件夹? 我目前的yaml文件:

 artifacts: files: - folder/myfile.js - node_modules/**/* discard-paths: yes 

如果有人可以提供解决scheme,这将是很好的?

如果解决scheme中不包含更改的github-repo文件夹结构,我想在其他文件中也重复这个用于创build其他lambda函数的repo。

编辑:

我使用下面的yaml文件,一切工作正常后@awsnitin回答

 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 

不幸的是丢弃path在这种情况下不起作用。 最佳select是将必要的文件作为构build逻辑(buildspec.yml)的一部分复制到新文件夹中,并在工件部分中指定该文件夹。 这是一个示例buildspec文件

 post_build: commands: - mkdir build-output - cp -R folder/myfile.js node_modules/ build-output artifacts: files: - build-output/**/*