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

feat(cli): hotswap deployments #15748

Merged
merged 9 commits into from
Sep 2, 2021
Merged

feat(cli): hotswap deployments #15748

merged 9 commits into from
Sep 2, 2021

Conversation

skinny85
Copy link
Contributor

@skinny85 skinny85 commented Jul 24, 2021

This is the first PR implementing the "Accelerated personal deployments" RFC.

It adds a (boolean) --hotswap flag to the deploy command that attempts to perform a short-circuit deployment, updating the resource directly, and skipping CloudFormation.
If we detect that the current change cannot be short-circuited
(because it contains an infrastructure change to the CDK code, most likely),
we fall back on performing a full CloudFormation deployment,
same as if cdk deploy was called without the --hotswap flag.

In this PR, the new switch supports only Lambda functions. Later PRs will add support for new resource types.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@skinny85 skinny85 requested a review from eladb July 24, 2021 19:46
@skinny85 skinny85 self-assigned this Jul 24, 2021
@gitpod-io
Copy link

gitpod-io bot commented Jul 24, 2021

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 24, 2021
packages/aws-cdk/README.md Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/accelerated-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/accelerated-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/accelerated-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/accelerated-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/accelerated-deployments.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/accelerated-deployments.ts Outdated Show resolved Hide resolved
@skinny85
Copy link
Contributor Author

@eladb thanks for the review! Incorporated all of your comments, would appreciate another pass!

@eladb eladb changed the title feat(cli): add the --accelerated option to the deploy command feat(cli): hotswap deployments Jul 27, 2021
eladb
eladb previously requested changes Jul 29, 2021
packages/aws-cdk/README.md Outdated Show resolved Hide resolved
packages/aws-cdk/README.md Outdated Show resolved Hide resolved
packages/aws-cdk/README.md Outdated Show resolved Hide resolved
packages/aws-cdk/README.md Outdated Show resolved Hide resolved
packages/aws-cdk/README.md Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/deploy-stack.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/deploy-stack.ts Outdated Show resolved Hide resolved
packages/aws-cdk/README.md Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/hotswap/lambda-functions.ts Outdated Show resolved Hide resolved
packages/aws-cdk/lib/api/hotswap-deployments.ts Outdated Show resolved Hide resolved
@skinny85
Copy link
Contributor Author

@eladb thanks for the review! Incorporated all of your comments, would appreciate another pass.

packages/aws-cdk/README.md Show resolved Hide resolved
packages/aws-cdk/bin/cdk.ts Show resolved Hide resolved
packages/aws-cdk/lib/api/deploy-stack.ts Outdated Show resolved Hide resolved
@skinny85
Copy link
Contributor Author

@BenChaimberg thanks a lot for the review! I've pushed a new revision addressing your comments, would appreciate another pass!

@skinny85 skinny85 requested a review from BenChaimberg August 28, 2021 00:21
return hotswapDeploymentResult;
}
// could not short-circuit the deployment, perform a full CFN deploy instead
print('Could not perform a hotswap deployment, as the stack %s contains non-Asset changes', stackArtifact.displayName);
Copy link
Contributor

Choose a reason for hiding this comment

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

💅 Putting this here is not extensible. The tryHotswapDeployment function should probably return a reason saying why it couldn't do it.

Copy link
Contributor Author

@skinny85 skinny85 Aug 30, 2021

Choose a reason for hiding this comment

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

Can you elaborate what would you like to see here? Should the Lambda "hotswap detector" return something like "Change is to property 'X', while only changes to the 'Code' property are supported", or something like that? Or did you mean something else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I meant something like that.

packages/aws-cdk/lib/api/deploy-stack.ts Show resolved Hide resolved
const resolvedEnv = await sdkProvider.resolveEnvironment(stackArtifact.environment);
const hotswappableChanges = findAllHotswappableChanges(stackChanges, {
...assetParams,
'AWS::Region': resolvedEnv.region,
Copy link
Contributor

Choose a reason for hiding this comment

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

AWS::Partition as well probably

And I'd think AWS::URLSuffix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but where can we get those from? I'd rather avoid doing more service calls here (this is supposed to be as fast as possible).

Copy link
Contributor

Choose a reason for hiding this comment

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

cdk-assets has code to get these values.

@skinny85
Copy link
Contributor Author

@rix0rrr @BenChaimberg thanks for the review, the PR should be ready for another pass!

Copy link
Contributor

@BenChaimberg BenChaimberg left a comment

Choose a reason for hiding this comment

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

lgtm

@skinny85 skinny85 added the pr/do-not-merge This PR should not be merged at this time. label Aug 30, 2021
Copy link
Contributor Author

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

@calvin-cc In general, looks great! 2 questions.

packages/aws-cdk/bin/cdk.ts Outdated Show resolved Hide resolved
packages/aws-cdk/bin/cdk.ts Outdated Show resolved Hide resolved
Comment on lines 329 to 335
let disableRollback;

if (options.rollback === undefined && options.hotswap === true) {
disableRollback = { DisableRollback: true };
} else {
disableRollback = options.rollback === false ? { DisableRollback: true } : undefined;
}
Copy link
Contributor Author

@skinny85 skinny85 Sep 1, 2021

Choose a reason for hiding this comment

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

We're repeating the { DisableRollback: true } expression for no reason here.

Suggested change
let disableRollback;
if (options.rollback === undefined && options.hotswap === true) {
disableRollback = { DisableRollback: true };
} else {
disableRollback = options.rollback === false ? { DisableRollback: true } : undefined;
}
const shouldDisableRollback = (options.rollback === undefined && options.hotswap === true) || options.rollback === false;
const disableRollback = shouldDisableRollback ? { DisableRollback: true } : undefined;

Copy link
Contributor Author

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Looks great! One more small simplification.

@@ -196,7 +203,8 @@ export class CdkToolkit {
usePreviousParameters: options.usePreviousParameters,
progress: options.progress,
ci: options.ci,
rollback: options.rollback,
rollback: shouldDisableRollback ? false : true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since you moved this here, we can simplify further:

Suggested change
rollback: shouldDisableRollback ? false : true,
rollback: options.rollback === undefined && options.hotswap ? false : options.rollback,

And get rid of the shouldDisableRollback variable.

Copy link
Contributor Author

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

We're very close! Just revert the readonly change, and move the logic down a little bit.

@@ -181,7 +185,16 @@ export interface DeployStackOptions {
*
* @default true
*/
readonly rollback?: boolean;
rollback?: boolean;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like changing this to not be readonly. See my solution below on how to handle this in a more idiomatic way. This change should be reverted.

Comment on lines 253 to 254
const shouldDisableRollback = (options.rollback === undefined && options.hotswap === true) || options.rollback === false;
options.rollback = shouldDisableRollback ? false : true;
Copy link
Contributor Author

@skinny85 skinny85 Sep 2, 2021

Choose a reason for hiding this comment

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

Not a fan of doing this here. tryHotswapDeployment() doesn't use this option, so dealing with it here is a little confusing to me. Let's move this down to prepareAndExecuteChangeSet(), where it's actually used.

@@ -250,6 +286,7 @@ export async function deployStack(options: DeployStackOptions): Promise<DeploySt

debug(`Attempting to create ChangeSet with name ${changeSetName} to ${update ? 'update' : 'create'} stack ${deployName}`);
print('%s: creating CloudFormation changeset...', colors.bold(deployName));
const executionId = uuid.v4();
const changeSet = await cfn.createChangeSet({
StackName: deployName,
ChangeSetName: changeSetName,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The defaulting of rollback should be done here. I can't comment on the line, because it wasn't changed, but it should be done on line 332.

Copy link
Contributor Author

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

@comcalvi looks great! Thanks for the change. I will merge this PR in sec.

@skinny85 skinny85 removed the pr/do-not-merge This PR should not be merged at this time. label Sep 2, 2021
@skinny85 skinny85 dismissed stale reviews from BenChaimberg and eladb September 2, 2021 21:50

Mergify dismissed it accidentally

@mergify
Copy link
Contributor

mergify bot commented Sep 2, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 3bbe048
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 6e55c95 into aws:master Sep 2, 2021
@mergify
Copy link
Contributor

mergify bot commented Sep 2, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@skinny85 skinny85 deleted the cdk-watch branch September 2, 2021 22:37
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Sep 6, 2021
This is the first PR implementing the ["Accelerated personal deployments" RFC](https://github.com/aws/aws-cdk-rfcs/blob/master/text/0001-cdk-update.md).

It adds a (boolean) `--hotswap` flag to the `deploy` command that attempts to perform a short-circuit deployment, updating the resource directly, and skipping CloudFormation.
If we detect that the current change cannot be short-circuited
(because it contains an infrastructure change to the CDK code, most likely),
we fall back on performing a full CloudFormation deployment,
same as if `cdk deploy` was called without the `--hotswap` flag.

In this PR, the new switch supports only Lambda functions. Later PRs will add support for new resource types.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
david-doyle-as24 pushed a commit to david-doyle-as24/aws-cdk that referenced this pull request Sep 7, 2021
This is the first PR implementing the ["Accelerated personal deployments" RFC](https://github.com/aws/aws-cdk-rfcs/blob/master/text/0001-cdk-update.md).

It adds a (boolean) `--hotswap` flag to the `deploy` command that attempts to perform a short-circuit deployment, updating the resource directly, and skipping CloudFormation.
If we detect that the current change cannot be short-circuited
(because it contains an infrastructure change to the CDK code, most likely),
we fall back on performing a full CloudFormation deployment,
same as if `cdk deploy` was called without the `--hotswap` flag.

In this PR, the new switch supports only Lambda functions. Later PRs will add support for new resource types.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@revmischa
Copy link
Contributor

Thanks so much for the work on this! I'm eager to try it out but it doesn't seem to be functional yet for nested stacks. Are there plans to support that?

@skinny85
Copy link
Contributor Author

@revmischa has opened #16508 to track this, so let's move the conversation there 🙂.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants