Skip to main content

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 :

  1. In project.json on package stage we:
    • build production ready code
    • go to dist folder and install npm packages
    • create zip archive
    • run package stage from serverless framework
  2. In serverless.yml we specified path to created ZIP (custom->artifactPath) and use it in package option (package->artifact)
  3. In project.json on deploy stage we: - run package stage - 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. Both deploy and package targets have parameter :

    stage - Desired environment. [dev, prod]

So the command to run to deploy your function is: nx run ${action-name}:deploy --stage={stage}