-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): hotswap deployments for StepFunctions State Machines (#16489)
This adds support for `StepFunctions::StateMachines` to be hotswapped. Only changes to the `DefinitionString` property will trigger hotswaps. Changes to other properties (or resources, except Lambda functions) will require full deployments. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
11 changed files
with
1,173 additions
and
141 deletions.
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
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
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
62 changes: 62 additions & 0 deletions
62
packages/aws-cdk/lib/api/hotswap/stepfunctions-state-machines.ts
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { ISDK } from '../aws-auth'; | ||
import { ChangeHotswapImpact, ChangeHotswapResult, HotswapOperation, HotswappableChangeCandidate, establishResourcePhysicalName } from './common'; | ||
import { EvaluateCloudFormationTemplate } from './evaluate-cloudformation-template'; | ||
|
||
export async function isHotswappableStateMachineChange( | ||
logicalId: string, change: HotswappableChangeCandidate, evaluateCfnTemplate: EvaluateCloudFormationTemplate, | ||
): Promise<ChangeHotswapResult> { | ||
const stateMachineDefinitionChange = await isStateMachineDefinitionOnlyChange(change, evaluateCfnTemplate); | ||
if (stateMachineDefinitionChange === ChangeHotswapImpact.REQUIRES_FULL_DEPLOYMENT || | ||
stateMachineDefinitionChange === ChangeHotswapImpact.IRRELEVANT) { | ||
return stateMachineDefinitionChange; | ||
} | ||
|
||
const machineNameInCfnTemplate = change.newValue?.Properties?.StateMachineName; | ||
const machineName = await establishResourcePhysicalName(logicalId, machineNameInCfnTemplate, evaluateCfnTemplate); | ||
if (!machineName) { | ||
return ChangeHotswapImpact.REQUIRES_FULL_DEPLOYMENT; | ||
} | ||
|
||
return new StateMachineHotswapOperation({ | ||
definition: stateMachineDefinitionChange, | ||
stateMachineName: machineName, | ||
}); | ||
} | ||
|
||
async function isStateMachineDefinitionOnlyChange( | ||
change: HotswappableChangeCandidate, evaluateCfnTemplate: EvaluateCloudFormationTemplate, | ||
): Promise<string | ChangeHotswapImpact> { | ||
const newResourceType = change.newValue.Type; | ||
if (newResourceType !== 'AWS::StepFunctions::StateMachine') { | ||
return ChangeHotswapImpact.REQUIRES_FULL_DEPLOYMENT; | ||
} | ||
|
||
const propertyUpdates = change.propertyUpdates; | ||
for (const updatedPropName in propertyUpdates) { | ||
// ensure that only changes to the definition string result in a hotswap | ||
if (updatedPropName !== 'DefinitionString') { | ||
return ChangeHotswapImpact.REQUIRES_FULL_DEPLOYMENT; | ||
} | ||
} | ||
|
||
return evaluateCfnTemplate.evaluateCfnExpression(propertyUpdates.DefinitionString.newValue); | ||
} | ||
|
||
interface StateMachineResource { | ||
readonly stateMachineName: string; | ||
readonly definition: string; | ||
} | ||
|
||
class StateMachineHotswapOperation implements HotswapOperation { | ||
constructor(private readonly stepFunctionResource: StateMachineResource) { | ||
} | ||
|
||
public async apply(sdk: ISDK): Promise<any> { | ||
// not passing the optional properties leaves them unchanged | ||
return sdk.stepFunctions().updateStateMachine({ | ||
// even though the name of the property is stateMachineArn, passing the name of the state machine is allowed here | ||
stateMachineArn: this.stepFunctionResource.stateMachineName, | ||
definition: this.stepFunctionResource.definition, | ||
}).promise(); | ||
} | ||
} |
Oops, something went wrong.