-
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.
Introduce the HotswappableChange abstraction.
- Loading branch information
Showing
3 changed files
with
225 additions
and
170 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as cfn_diff from '@aws-cdk/cloudformation-diff'; | ||
import { CloudFormation } from 'aws-sdk'; | ||
import { ISDK } from '../aws-auth'; | ||
import { evaluateCfn } from '../util/cloudformation/evaluate-cfn'; | ||
|
||
export interface ListStackResources { | ||
listStackResources(): Promise<CloudFormation.StackResourceSummary[]>; | ||
} | ||
|
||
/** | ||
* An interface that represents a change that can be short-circuited. | ||
* | ||
* @param T the type of the change that is passed | ||
*/ | ||
export interface HotswappableChange<T> { | ||
hotswap(t: T, sdk: ISDK, stackResources: ListStackResources): Promise<void>; | ||
} | ||
|
||
/** | ||
* For old-style synthesis which uses CFN Parameters, | ||
* the Code properties can have the values of complex CFN expressions. | ||
* For new-style synthesis of env-agnostic stacks, | ||
* the Fn::Sub expression is used for the Asset bucket. | ||
* Evaluate the CFN expressions to concrete string values which we need for the | ||
* updateFunctionCode() service call. | ||
*/ | ||
export function stringifyPotentialCfnExpression(value: any, assetParamsWithEnv: { [key: string]: string }): string { | ||
// if we already have a string, nothing to do | ||
if (value == null || typeof value === 'string') { | ||
return value; | ||
} | ||
|
||
// otherwise, we assume this is a CloudFormation expression that we need to evaluate | ||
return evaluateCfn(value, assetParamsWithEnv); | ||
} | ||
|
||
export function assetMetadataChanged(change: cfn_diff.ResourceDifference): boolean { | ||
return !!change.newValue?.Metadata['aws:asset:path']; | ||
} |
Oops, something went wrong.