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

Lambda code asset reuse #2595

Closed
mitchlloyd opened this issue May 20, 2019 · 1 comment
Closed

Lambda code asset reuse #2595

mitchlloyd opened this issue May 20, 2019 · 1 comment
Assignees
Labels
feature-request A feature should be added or improved.

Comments

@mitchlloyd
Copy link
Contributor

There are 2 new CDK features that seem to nearly address a use case I have.

First we have the ability to --build-exclude an asset, letting us reuse the previously uploaded asset for a Lambda. Secondly a feature exposing an asset fingerprint and asset sha256 hash is in progress.

With CDK I'd like to express: "when there is no local code asset, don't deploy a new code asset and don't create a new Lambda version".

// This is some hypothetical API that signals asset reuse.
let codeAsset = lambda.Code.previousAsset();
if (fs.existsSync(codePath)) {
  codeAsset = lambda.Code.asset(codePath);
}

// Everything else from here on out is typical Lambda use today
const lambdaFunction = new lambda.Function(this, 'Resource', {
  code: codeAsset,
  // ...
});

const alias = new lambda.Alias(this, 'LiveAlias', {
  aliasName: 'Live',
  description: 'Live alias used to shift traffic during deployments.',
  version: lambdaFunction.addVersion(codeAsset.sourceHash, codeAsset.bundleHash),
});

PreviousAsset would both mark the asset to be reused (i.e. keep previous deployment parameters) and expose the previous hashes for versioning.

Does this seems possible? Am I missing the boat and there is a better way to accomplish this workflow?

@mitchlloyd mitchlloyd added the feature-request A feature should be added or improved. label May 20, 2019
@ghost ghost mentioned this issue Nov 7, 2019
2 tasks
@eladb
Copy link
Contributor

eladb commented Jan 23, 2020

This now happens by default. Assets are identified by the hash of their source and won't get uploaded if already exists.

@eladb eladb closed this as completed Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

2 participants