Amplify-cli: Best practice to share local code between lambdas?

Created on 20 Jun 2019  路  5Comments  路  Source: aws-amplify/amplify-cli

* Which Category is your question related to? *
Functions

* What AWS Services are you utilizing? *
Lambda + AppSync

* Provide additional details e.g. code snippets *
I have several lambdas and there is common code I developed needed by a few them. I wanted to put this code in a private package that these lambdas refer to in package.json. There are different ways to do this, I ended up investigating lerna and yarn. I went with yarn since lerna requires the packages to be published in an npm registry but these packages are private. Yarn workspaces on the other hand do not need a remote registry. I ran into an issue with Yarn however and I had to use their 'nohoist' option to get the Lambdas to install their packages in their direct node_modules dir rather than the root project node_modules. See issue here https://github.com/yarnpkg/yarn/issues/6412.

It would be nice if the amplify cli had a recommended way of sharing locally developed packages between functions where all this is documented for us developers who are a little new to monorepos and serverless functions.

feature-request functions

Most helpful comment

I think it is time for amplify to support Lambda Layers! Locally and during deploy

All 5 comments

I got yarn working and the lambda function deployed but looks like amplify cli does not follow symlinks when packaging lambdas! The deployed lambda package does not have my local package dependency.

See https://github.com/aws-amplify/amplify-cli/issues/1077#issuecomment-484254817 and https://github.com/aws-amplify/amplify-cli/issues/703

So what is the best way to share local code between lambdas currently?

My yarn setup is now working but I have to run this command to resolve symlinks before amplify push: cp -RL node_modules/ tmp/ && rm -rf node_modules/ && mv tmp node_modules

I think it is time for amplify to support Lambda Layers! Locally and during deploy

@hisham We're tracking support for lambda layers in #703. Closing this as a duplicate.

My yarn setup is now working but I have to run this command to resolve symlinks before amplify push: cp -RL node_modules/ tmp/ && rm -rf node_modules/ && mv tmp node_modules

Really solid workaround that supports symlinked libraries in lambdas. Thanks @hisham!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicksmithr picture nicksmithr  路  3Comments

adriatikgashi picture adriatikgashi  路  3Comments

jexh picture jexh  路  3Comments

zjullion picture zjullion  路  3Comments

davo301 picture davo301  路  3Comments