-
Notifications
You must be signed in to change notification settings - Fork 4k
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(cdk): Resolve cross stack and default parameters for hotswaps #27195
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0a38e5a
fix nested stack hotswap
Amplifiyer e454d9e
Add AppSync graphqlschema and pipeline resolvers as hotswappable
Amplifiyer 7b741ec
Build retry for updating AppSync functions when they fail due to conc…
Amplifiyer a93289c
update tests for appsync resolver and functions hotswap
Amplifiyer bd845dd
update tests for appsync graphql schema
Amplifiyer dc6547e
update tests for nested stacks hotswap updates
Amplifiyer 208a36b
revert appsync changes
Amplifiyer 5f77d88
revert appsync changes
Amplifiyer 4261163
revert appsync changes
Amplifiyer 638bf31
Merge branch 'main' into nested_stack_hotswap
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import * as cxapi from '@aws-cdk/cx-api'; | |
import * as chalk from 'chalk'; | ||
import { ISDK, Mode, SdkProvider } from './aws-auth'; | ||
import { DeployStackResult } from './deploy-stack'; | ||
import { EvaluateCloudFormationTemplate, LazyListStackResources } from './evaluate-cloudformation-template'; | ||
import { EvaluateCloudFormationTemplate } from './evaluate-cloudformation-template'; | ||
import { isHotswappableAppSyncChange } from './hotswap/appsync-mapping-templates'; | ||
import { isHotswappableCodeBuildProjectChange } from './hotswap/code-build-projects'; | ||
import { ICON, ChangeHotswapResult, HotswapMode, HotswappableChange, NonHotswappableChange, HotswappableChangeCandidate, ClassifiedResourceChanges, reportNonHotswappableChange } from './hotswap/common'; | ||
|
@@ -24,6 +24,7 @@ const RESOURCE_DETECTORS: { [key:string]: HotswapDetector } = { | |
'AWS::Lambda::Function': isHotswappableLambdaFunctionChange, | ||
'AWS::Lambda::Version': isHotswappableLambdaFunctionChange, | ||
'AWS::Lambda::Alias': isHotswappableLambdaFunctionChange, | ||
|
||
// AppSync | ||
'AWS::AppSync::Resolver': isHotswappableAppSyncChange, | ||
'AWS::AppSync::FunctionConfiguration': isHotswappableAppSyncChange, | ||
|
@@ -54,21 +55,21 @@ export async function tryHotswapDeployment( | |
// create a new SDK using the CLI credentials, because the default one will not work for new-style synthesis - | ||
// it assumes the bootstrap deploy Role, which doesn't have permissions to update Lambda functions | ||
const sdk = (await sdkProvider.forEnvironment(resolvedEnv, Mode.ForWriting)).sdk; | ||
// The current resources of the Stack. | ||
// We need them to figure out the physical name of a resource in case it wasn't specified by the user. | ||
// We fetch it lazily, to save a service call, in case all hotswapped resources have their physical names set. | ||
const listStackResources = new LazyListStackResources(sdk, stackArtifact.stackName); | ||
Comment on lines
-57
to
-60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this has been moved elsewhere, could you explain why? I don't see why this is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Answered here #27195 (comment) |
||
|
||
const currentTemplate = await loadCurrentTemplateWithNestedStacks(stackArtifact, sdk); | ||
|
||
const evaluateCfnTemplate = new EvaluateCloudFormationTemplate({ | ||
stackName: stackArtifact.stackName, | ||
template: stackArtifact.template, | ||
parameters: assetParams, | ||
account: resolvedEnv.account, | ||
region: resolvedEnv.region, | ||
partition: (await sdk.currentAccount()).partition, | ||
urlSuffix: (region) => sdk.getEndpointSuffix(region), | ||
listStackResources, | ||
sdk, | ||
nestedStackNames: currentTemplate.nestedStackNames, | ||
}); | ||
|
||
const currentTemplate = await loadCurrentTemplateWithNestedStacks(stackArtifact, sdk); | ||
const stackChanges = cfn_diff.diffTemplate(currentTemplate.deployedTemplate, stackArtifact.template); | ||
const { hotswappableChanges, nonHotswappableChanges } = await classifyResourceChanges( | ||
stackChanges, evaluateCfnTemplate, sdk, currentTemplate.nestedStackNames, | ||
|
@@ -231,9 +232,8 @@ async function findNestedHotswappableChanges( | |
}; | ||
} | ||
|
||
const nestedStackParameters = await evaluateCfnTemplate.evaluateCfnExpression(change.newValue?.Properties?.Parameters); | ||
const evaluateNestedCfnTemplate = evaluateCfnTemplate.createNestedEvaluateCloudFormationTemplate( | ||
new LazyListStackResources(sdk, nestedStackName), change.newValue?.Properties?.NestedTemplate, nestedStackParameters, | ||
const evaluateNestedCfnTemplate = await evaluateCfnTemplate.createNestedEvaluateCloudFormationTemplate( | ||
nestedStackName, change.newValue?.Properties?.NestedTemplate, change.newValue?.Properties?.Parameters, | ||
); | ||
|
||
const nestedDiff = cfn_diff.diffTemplate( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
why do we need this here?
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.
In current CDK,
evaluate-cloudformation-template
can only evaluate CFN (Intrinsic) Fn references for resources in the same stack (Let's call it A) and hence it is passed a list of A's resources to assist in evaluation.However the problem comes when a resource in A stack references resources in a different stack (Let's call it B). In that case
evaluate-cloudformation-template
of A has no knowledge of it.This PR refactors
evaluate-cloudformation-template
in a way that it can recursively instantiate anotherevaluate-cloudformation-template
for the referenced stack. And to do that, A'sevaluate-cloudformation-template
needs to pass in the list of B's resources while creating another instance and hence thesdk
needs to be passed in for the A'sevaluate-cloudformation-template
so that it can call B'slistResources
Now, instead of having the caller to get the list of stack's resources and pass it to
evaluate-cloudformation-template
, it's better forevaluate-cloudformation-template
to manage it on it's own, since these resources are specifically being used by theevaluate-cloudformation-template
and instead just pass the sdk rather than bothsdk
and thestackResources