ZIP Lambda
There is a problem with NX tool to say serverless framework from which folder get the code and deploy it to AWS. This problem was solved by excluding the package stage from the serverless framework. Instead of serverless framework we do it manually. So order to achieve it we need to execute next steps :
- In
project.jsononpackagestage we:- build production ready code
- go to dist folder and install npm packages
- create zip archive
- run
packagestage from serverless framework
- In serverless.yml we specified path to created ZIP (custom->artifactPath) and use it in package option (package->artifact)
- In
project.jsonondeploystage we: - runpackagestage - run deploy command on serverless framework, which will take created ZIP, upload it to s3 on AWS and assign with Lambda function, check resources that need to be created for the function to work and create them. Bothdeployandpackagetargets have parameter :stage - Desired environment. [dev, prod]
So the command to run to deploy your function is:
nx run ${action-name}:deploy --stage={stage}