CreatesanAWSLambdaLayersstructurethatisoptimizedfor:LambdaLayerdirectorystructure,compiledlibrarycompatibility,andminimalfilesize.
Thisrepowascreatedtoaddresstheseissues:
ManymethodsofcreatingLambdazipfilesforPythonfunctionsdon'tworkforLambdaLayersThisisduetothefactLambdaLayersrequirespecificlibrarypathswithinthezip,whereregularLambdazipsdon'tCompileddependenciesmustbecreatedinanenvironmentthatmatchestheLambdaruntimeReducesizeofthelayerbyremovingunnecessarylibrariesandfilesNote:ThisscriptrequiresDockerandusesacontainertomimictheLambdaenvironment.
FeaturesBuildseitherazipfileorarawdirectorystrucutre(e.g.ifyouwanttouseframeworkslikeServerlessforpackaging)containingPythondependenciesandplacesthelibrariesintotheproperdirectorystructureforlambdalayersEnsurescompiledlibrariesarecompatiblewithLambdaenvironmentbyusingthelambci/lambdaDockercontainerthatmimicsthelambdaruntimeenvironmentOptimizedthezipsizebyremoving.pycfilesandunnecessarylibrariesAllowsspecifyinglambdasupportedpythonversions:2.7,3.6,3.7and3.8Automaticallysearchesforrequirements.txtfileinseverallocations:samedirectoryasscriptparentdirectoryorscript(usefulwhenusedassubmodule)functionsub-directoryoftheparentdirectoryInstallationThisfunctioncanbeclonedforstandaloneuse,intoaparentrepooraddedasasubmodule.
Cloneforstandaloneuseorwithinarepo:
#Ifinstallingintoanexisitingrepo,navigatetorepodirgitclone--depth1https://github.com/tobilg/python-lambda-layer-builder_build_layerAlternatively,addasasubmodule:
cd{reporoot}gitsubmoduleaddhttps://github.com/tobilg/python-lambda-layer-builder_build_layer#Updatesubmodulegitsubmoduleupdate--init--recursive--remoteUsage$./build.sh-hAWSLambdaLayerBuilderforPythonLibrariesUsage:build.sh[-pPYTHON_VER][-nNAME][-f][-r][-h][-v]-pPYTHON_VER:Pythonversiontouse:2.7,3.6,3.7,3.8(default3.7)-nNAME:Nameofthelayer-fREQ_PATH:Pathtorequirementsfile-r:Rawmode,don'tziplayercontents-d:Don'tinstallPythondependencies-s:Don'tstrip.sofiles-h:Help-v:Displaybuild.shversionRunthebuilderwiththecommand./build.shor_build_layer/build.shifinstalledinsub-dirItusesthefirstrequirements.txtfilefoundintheselocations(inorder):Inputonthecommandlineusingthe-fswitchSamedirectoryasscriptParentdirectoryofscript(usefulwhenusedassubmodule)Functionsub-directoryoftheparentdirectory(usefulwhenusedassubmodule)OptionallyspecifyPythonVersion-pPYTHON_VER-specifiesthePythonversion:2.7,3.6,3.7,3.8(default3.7)CustomcleaninglogicYoucaneditthe_clean.shfileifyouwanttoaddcustomcleaninglogicforthebuildoftheLambdalayer.Theabovepartofthefilemuststayintact:
#!/usr/bin/envbash#Changetoworkingdirectorycd$1#-----DON'TCHANGETHEABOVE-----#Cleaningstatements#-----CHANGEHERE-----rmtest.xtThe_make.shscriptwillthenexecutethecommandsafterthePythonpackageshavebeeninstalled.
UninstallIfinstalledassubmoduleandneedtoremove
#Removethesubmoduleentryfrom.git/configgitsubmoduledeinit-f$submodulepath#Removethesubmoduledirectoryfromthesuperproject's.git/modulesdirectoryrm-rf.git/modules/$submodulepath#Removetheentryin.gitmodulesandremovethesubmoduledirectorylocatedatpath/to/submodulegitrm-f$submodulepath#removeentryinsubmodulesfilegitconfig-f.git/config--remove-sectionsubmodule.$submodulepath
评论