Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix lambda logical version id for layers in same stack #8066
Fix lambda logical version id for layers in same stack #8066
Changes from 11 commits
3e6fa90
34b0877
91e3077
f927470
f93b1aa
b4ee79a
3a01dc9
b51b81e
6d412bc
b5cb580
3080dd3
14de011
001f440
8678062
619050c
781aa98
a6ccbac
3ad5651
bccd773
997c0f0
8df8aac
a6ec21d
8b21863
18e6b1f
231cf14
4941a15
62cd779
625aea8
d7704ec
b1571c3
9ee00b4
38c867e
ff09d04
6e0be19
193c516
7ad4818
9e08cf5
c8be293
eee300e
76bf822
a9baf17
6967213
b3cea34
7c3ac73
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks as not necessarily equivalent to:
serverless/lib/plugins/aws/package/compile/layers/index.js
Lines 31 to 34 in 01a03d1
I believe safest way, would be to resolve an actual layer configuration object for given layer, and follow above logic to resolve path to layer artifact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into addressing this but an issue is that in the linked logic it uses
layerObject
which is defined using:where
layerName
is actually the layer key used in the serverless.yml file, not the specific layer name field.So the challenge would be how to get the serverless.yml layer key from the Ref key provided under the function layer, i.e. how to get
testLayer
from{ Ref: TestLayerLambdaLayer }
and alsoTestLayer
from{ Ref: TestLayerLambdaLayer}
as the key is capitalized. Any ideas? Obviously could just split byLambdaLayer
then if an error is thrown try with lowercase first letter, but it wouldn't be very clean.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually tried the split/lowercase method and it doesn't seem too bad, but let me know what you think: a6ec21d#diff-771a8504e96d8db95f70f2cca6e3a906R458
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably most bulletproof way, would be to introduce a hidden property on layer resource, that references
layerObject
We can do following
At
serverless/lib/plugins/aws/package/compile/layers/index.js
Line 28 in 5f85543
It's safe for CF template handling, as hidden properties don't go down to JSON, and in our logic we can access the config as:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is possible as it looks like most resources are added using
_.merge(this.serverless.service.provider.compiledCloudFormationTemplate...
which will drop the hidden (enumerable: false
) value. Ifenumerable: true
then it seems to go down to JSON.Is there somewhere else on the main serverless object it could be stored? Could add a method to
lib/classes/Service.js
but not sure that would make it much better. I wonder if there was an "official" way of resolving between the two then this https://github.com/serverless/serverless/blob/master/lib/plugins/aws/package/compile/functions/index.js#L449 could support just a list of layer object names from serverless.yml, rather than having to use the{ Ref: MyLayerLambdaLayer}
syntax for layers within the same stack.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may replace
_.merge
withObject.assign
. Note_.merge
is used in many places without a valid reasons, and as it's a deep merge occasionally it causes an unexpected issues.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now changed here: 231cf14 (plus this fix for the fallback condition, not sure which cases this would be used: 625aea8)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use Bluebird` functions which do not have native counterparts.
We should use
BbPromise.all
insteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been updated now, but I realized that both approaches in their current state will run asynchronously on the same hash object. I'm not sure if there could be a race condition or something if
hash.write(chunk)
calls on the same object collide.A potential fix would be to rewrite
addFileContentsToHash
to return a new string or hash object representing the file. Once all promises finish, the array of strings/hashes could then be combined and added to the versionId hash. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, it won't be deterministic then. We need to run it sequentially, I believe you can achieve it as:
Note that also
layerZipFilePaths
order needs to also be deterministicThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this should be done now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's reuse already resolved
layerProperties
(nice if namedlayerConfigurations
) in previous block.Also if I see correctly this logic simply removes
S3Key
properties, that can be done simpler way via:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem to be addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly I think this should be covered by 14de011#diff-771a8504e96d8db95f70f2cca6e3a906R475
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem. Note that
layerConfigurations
are still resolved twice in code as proposed:serverless/lib/plugins/aws/package/compile/functions/index.js
Lines 452 to 455 in bccd773
serverless/lib/plugins/aws/package/compile/functions/index.js
Lines 476 to 479 in bccd773
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it is now moved out of the block and used twice.