Both pixelchessResolveCreateConnectionMutation and pixelchessResolveSetPlayerMutation contain identical functions called getPlayers. These two functions should be replaced with a single function which both pixelchessResolveCreateConnectionMutation and pixelchessResolveSetPlayerMutation can access.
There are at least two ways to accomplish this.
Option 1: Lambda Function
Copy the getPlayers function into a lambda function.
Configure the lambda function permissions.
Invoke the lambda function from both pixelchessResolveCreateConnectionMutation and pixelchessResolveSetPlayerMutation.
Remove the original getPlayers functions from both pixelchessResolveCreateConnectionMutation and pixelchessResolveSetPlayerMutation.
Pros:
Simpler and more fool-proof (less work up front)
Cons:
More boilerplate code in lambda functions
More lambda function invocations (slower and more expensive)
Option 2: Utility Layer Package
Refactor the getPlayers function into the aws-lambda-utility-layer package.
Publish the newly updated package.
Update the lambda layer with the newly updated package.
Push changes to the lambda layer.
Reconfigure lambda layer version for both pixelchessResolveCreateConnectionMutation and pixelchessResolveSetPlayerMutation.
Require and invoke the utility function from both pixelchessResolveCreateConnectionMutation and pixelchessResolveSetPlayerMutation.
Remove the original getPlayers functions from both pixelchessResolveCreateConnectionMutation and pixelchessResolveSetPlayerMutation.
Pros:
Less boilerplate code in lambda functions (less work & cleaner to use)
Fewer lambda invocations (faster and cheaper)
Cons:
Updating lambda layers is not currently a good developer experience, and is fraught with issues. (more work up front)
getPlayers is not generic enough to warrant its addition to the aws-lambda-utility-layer package.
Option 3: Utility Layer /opt/ directory
Refactor the getPlayers function into the aws-lambda-utility-layer/opt/ folder.
Push changes to the lambda layer.
Reconfigure lambda layer version for both pixelchessResolveCreateConnectionMutation and pixelchessResolveSetPlayerMutation.
Require and invoke the utility function from both pixelchessResolveCreateConnectionMutation and pixelchessResolveSetPlayerMutation.
Remove the original getPlayers functions from both pixelchessResolveCreateConnectionMutation and pixelchessResolveSetPlayerMutation.
Pros:
Less boilerplate code in lambda functions (less work & cleaner to use)
Fewer lambda invocations (faster and cheaper)
No updates to npm package are required.
Cons:
Updating lambda layers is not currently a good developer experience, and is fraught with issues. (more work up front)
The Problem
Both
pixelchessResolveCreateConnectionMutation
andpixelchessResolveSetPlayerMutation
contain identical functions calledgetPlayers
. These two functions should be replaced with a single function which bothpixelchessResolveCreateConnectionMutation
andpixelchessResolveSetPlayerMutation
can access.There are at least two ways to accomplish this.
Option 1: Lambda Function
getPlayers
function into a lambda function.pixelchessResolveCreateConnectionMutation
andpixelchessResolveSetPlayerMutation
.getPlayers
functions from bothpixelchessResolveCreateConnectionMutation
andpixelchessResolveSetPlayerMutation
.Pros:
Cons:
Option 2: Utility Layer Package
getPlayers
function into theaws-lambda-utility-layer
package.pixelchessResolveCreateConnectionMutation
andpixelchessResolveSetPlayerMutation
.pixelchessResolveCreateConnectionMutation
andpixelchessResolveSetPlayerMutation
.getPlayers
functions from bothpixelchessResolveCreateConnectionMutation
andpixelchessResolveSetPlayerMutation
.Pros:
Cons:
getPlayers
is not generic enough to warrant its addition to theaws-lambda-utility-layer
package.Option 3: Utility Layer /opt/ directory
getPlayers
function into theaws-lambda-utility-layer
/opt/
folder.pixelchessResolveCreateConnectionMutation
andpixelchessResolveSetPlayerMutation
.pixelchessResolveCreateConnectionMutation
andpixelchessResolveSetPlayerMutation
.getPlayers
functions from bothpixelchessResolveCreateConnectionMutation
andpixelchessResolveSetPlayerMutation
.Pros:
Cons: