Skip to content
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

Optimize custom resources generation #7032

Merged
merged 8 commits into from Dec 3, 2019

Conversation

medikoo
Copy link
Contributor

@medikoo medikoo commented Dec 2, 2019

This should partially address custom resource installation efficiency issues, as discussed recently on slack.

It ensures that custom resource package is prepared once for installed Serverless versions, and in further runs existing package is re-used.

@medikoo medikoo added this to the 1.59.0 milestone Dec 2, 2019
Copy link
Contributor

@pmuens pmuens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @medikoo 👍

I like the idea of having a cache. However I'm concerned about npm versioning. What if AWS fixed a bug in their SDK and published a new version? In that case we would also need to publish a new Serverless Framework version to "invalidate" the cache.

I know that this might be an edge case we don't focus on. Just wanted to point this out...

@medikoo
Copy link
Contributor Author

medikoo commented Dec 2, 2019

What if AWS fixed a bug in their SDK and published a new version? In that case we would also need to publish a new Serverless Framework version to "invalidate" the cache.

It won't be the case, as when SLS version changes, it'll start caching to different path (note version token)

@medikoo medikoo self-assigned this Dec 2, 2019
@codecov-io
Copy link

codecov-io commented Dec 2, 2019

Codecov Report

Merging #7032 into master will decrease coverage by <.01%.
The diff coverage is 90.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7032      +/-   ##
==========================================
- Coverage    88.5%   88.49%   -0.01%     
==========================================
  Files         229      230       +1     
  Lines        8428     8447      +19     
==========================================
+ Hits         7459     7475      +16     
- Misses        969      972       +3
Impacted Files Coverage Δ
lib/plugins/aws/deploy/lib/uploadArtifacts.js 90.47% <ø> (ø) ⬆️
lib/plugins/aws/customResources/index.js 98.52% <100%> (-0.14%) ⬇️
lib/plugins/aws/lib/naming.js 99.21% <100%> (ø) ⬆️
lib/plugins/aws/customResources/generateZip.js 88.46% <88.46%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd93739...3a93697. Read the comment docs.

@medikoo medikoo requested a review from pmuens December 2, 2019 20:27
@pmuens
Copy link
Contributor

pmuens commented Dec 3, 2019

It won't be the case, as when SLS version changes, it'll start caching to different path (note version token)

Yes, exactly. However what about the following (artificially made-up) example:

  1. We ship v1.X which causes the CustomResources cache to be built.
  2. There's a bug in the AWS SDK which causes problems with our CustomResoruces code
  3. AWS fixes the bug and publishes a new version
  4. We need to release a v1.Y so that the cache is re-built because users of v1.X will still use the old, buggy aws-sdk from the cache

This might be a very rare circumstance we can ignore (or I'm missing something here). As the saying goes:

There are only two hard things in Computer Science ...

Copy link
Contributor

@pmuens pmuens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it with the following serverless.yml file and it works as expected! :shipit:

service: test-${self:custom.idx}

provider:
  name: aws
  runtime: nodejs10.x
  versionFunctions: false
  region: eu-central-1
  stage: dev

custom:
  idx: 0

functions:
  hello:
    handler: functions/handler.handler
    events:
      - eventBridge:
          pattern:
            source:
              - aws.cloudformation
            detail-type:
              - AWS API Call via CloudTrail
            detail:
              eventSource:
                - cloudformation.amazonaws.com

@medikoo
Copy link
Contributor Author

medikoo commented Dec 3, 2019

Yes, exactly. However what about the following (artificially made-up) example:

  1. We ship v1.X which causes the CustomResources cache to be built.
  2. There's a bug in the AWS SDK which causes problems with our CustomResoruces code
  3. AWS fixes the bug and publishes a new version
  4. We need to release a v1.Y so that the cache is re-built because users of v1.X will still use the old, buggy aws-sdk from the cache

This might be a very rare circumstance we can ignore (or I'm missing something here). As the saying goes:

Technically we're already immune to that issue. As currently also without bumping a framework version, it's very hard for users to upgrade aws-sdk, as both npm install serverless and npm update serverless won't update dependencies if the already installed versions matches version. range in package.json.

So I guess, either with this caching or not, it's only the new patch release that makes a solid fix for users.

@medikoo
Copy link
Contributor Author

medikoo commented Dec 3, 2019

I tried it with the following serverless.yml file and it works as expected!

I've also confirmed by running all integration tests (and picked one issue, which is already fixed in PR)

@medikoo medikoo merged commit 5e0c612 into master Dec 3, 2019
@medikoo medikoo deleted the improve-custom-resources-install branch December 3, 2019 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants