-
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(codedeploy): CodeDeploy deployment config constructs for Lambda …
…and ECS (#22159) CloudFormation now supports Lambda and ECS in the `AWS::CodeDeploy::DeploymentConfig` resource type. This PR adds L2 constructs specific to ECS and Lambda for that resource type. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
798f9e8
commit 6840d8e
Showing
34 changed files
with
1,753 additions
and
216 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
171 changes: 171 additions & 0 deletions
171
packages/@aws-cdk/aws-codedeploy/lib/base-deployment-config.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,171 @@ | ||
import { ArnFormat, Resource, Stack } from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
import { CfnDeploymentConfig } from './codedeploy.generated'; | ||
import { MinimumHealthyHosts } from './host-health-config'; | ||
import { TrafficRouting } from './traffic-routing-config'; | ||
import { arnForDeploymentConfig, validateName } from './utils'; | ||
|
||
/** | ||
* The base class for ServerDeploymentConfig, EcsDeploymentConfig, | ||
* and LambdaDeploymentConfig deployment configurations. | ||
*/ | ||
export interface IBaseDeploymentConfig { | ||
/** | ||
* The physical, human-readable name of the Deployment Configuration. | ||
* @attribute | ||
*/ | ||
readonly deploymentConfigName: string; | ||
|
||
/** | ||
* The ARN of the Deployment Configuration. | ||
* @attribute | ||
*/ | ||
readonly deploymentConfigArn: string; | ||
} | ||
|
||
/** | ||
* Construction properties of {@link BaseDeploymentConfig}. | ||
*/ | ||
export interface BaseDeploymentConfigOptions { | ||
/** | ||
* The physical, human-readable name of the Deployment Configuration. | ||
* @default - automatically generated name | ||
*/ | ||
readonly deploymentConfigName?: string; | ||
} | ||
|
||
/** | ||
* The compute platform of a deployment configuration | ||
*/ | ||
export enum ComputePlatform { | ||
/** | ||
* The deployment will target EC2 instances or on-premise servers | ||
*/ | ||
SERVER = 'Server', | ||
|
||
/** | ||
* The deployment will target a Lambda function | ||
*/ | ||
LAMBDA = 'Lambda', | ||
|
||
/** | ||
* The deployment will target an ECS server | ||
*/ | ||
ECS = 'ECS' | ||
} | ||
|
||
/** | ||
* Complete base deployment config properties that are required to be supplied by the implementation | ||
* of the BaseDeploymentConfig class. | ||
*/ | ||
export interface BaseDeploymentConfigProps extends BaseDeploymentConfigOptions { | ||
/** | ||
* The destination compute platform for the deployment. | ||
* | ||
* @default ComputePlatform.Server | ||
*/ | ||
readonly computePlatform?: ComputePlatform; | ||
|
||
/** | ||
* The configuration that specifies how traffic is shifted during a deployment. | ||
* Only applicable to ECS and Lambda deployments, and must not be specified for Server deployments. | ||
* @default None | ||
*/ | ||
readonly trafficRouting?: TrafficRouting; | ||
|
||
/** | ||
* Minimum number of healthy hosts. | ||
* @default None | ||
*/ | ||
readonly minimumHealthyHosts?: MinimumHealthyHosts; | ||
} | ||
|
||
/** | ||
* The base class for ServerDeploymentConfig, EcsDeploymentConfig, | ||
* and LambdaDeploymentConfig deployment configurations. | ||
* | ||
* @resource AWS::CodeDeploy::DeploymentConfig | ||
*/ | ||
export abstract class BaseDeploymentConfig extends Resource implements IBaseDeploymentConfig { | ||
/** | ||
* Import a custom Deployment Configuration for a Deployment Group defined outside the CDK. | ||
* | ||
* @param scope the parent Construct for this new Construct | ||
* @param id the logical ID of this new Construct | ||
* @param deploymentConfigName the name of the referenced custom Deployment Configuration | ||
* @returns a Construct representing a reference to an existing custom Deployment Configuration | ||
*/ | ||
protected static fromDeploymentConfigName(scope: Construct, id: string, deploymentConfigName: string): IBaseDeploymentConfig { | ||
ignore(id); | ||
const arn = Stack.of(scope).formatArn({ | ||
service: 'codedeploy', | ||
resource: 'deploymentconfig', | ||
resourceName: deploymentConfigName, | ||
arnFormat: ArnFormat.COLON_RESOURCE_NAME, | ||
}); | ||
return { | ||
deploymentConfigName: deploymentConfigName, | ||
deploymentConfigArn: arn, | ||
}; | ||
} | ||
|
||
/** | ||
* This method should be used only for static references to predefined deployment configurations, | ||
* like EcsDeploymentConfig.ALL_AT_ONCE | ||
* @param name the name of the referenced custom Deployment Configuration | ||
* @returns a reference to an existing custom Deployment Configuration | ||
*/ | ||
protected static deploymentConfig(name: string): IBaseDeploymentConfig { | ||
return { | ||
deploymentConfigName: name, | ||
deploymentConfigArn: arnForDeploymentConfig(name), | ||
}; | ||
} | ||
|
||
/** | ||
* The name of the deployment config | ||
* @attribute | ||
*/ | ||
public readonly deploymentConfigName: string; | ||
|
||
/** | ||
* The arn of the deployment config | ||
* @attribute | ||
*/ | ||
public readonly deploymentConfigArn: string; | ||
|
||
public constructor(scope: Construct, id: string, props?: BaseDeploymentConfigProps) { | ||
super(scope, id, { | ||
physicalName: props?.deploymentConfigName, | ||
}); | ||
|
||
// Traffic routing is not applicable to Server-based deployment configs | ||
if (props?.trafficRouting && (props?.computePlatform === undefined || props?.computePlatform === ComputePlatform.SERVER)) { | ||
throw new Error('Traffic routing config must not be specified for a Server-base deployment configuration'); | ||
} | ||
|
||
// Minimum healthy hosts is only applicable to Server-based deployment configs | ||
if (props?.minimumHealthyHosts && props?.computePlatform && props?.computePlatform !== ComputePlatform.SERVER) { | ||
throw new Error('Minimum healthy hosts config must only be specified for a Server-base deployment configuration'); | ||
} | ||
|
||
const resource = new CfnDeploymentConfig(this, 'Resource', { | ||
deploymentConfigName: this.physicalName, | ||
computePlatform: props?.computePlatform, | ||
trafficRoutingConfig: props?.trafficRouting?.bind(this), | ||
minimumHealthyHosts: props?.minimumHealthyHosts?._json, | ||
}); | ||
|
||
this.deploymentConfigName = this.getResourceNameAttribute(resource.ref); | ||
this.deploymentConfigArn = this.getResourceArnAttribute(arnForDeploymentConfig(resource.ref), { | ||
service: 'codedeploy', | ||
resource: 'deploymentconfig', | ||
resourceName: this.physicalName, | ||
arnFormat: ArnFormat.COLON_RESOURCE_NAME, | ||
}); | ||
|
||
this.node.addValidation({ validate: () => validateName('Deployment config', this.physicalName) }); | ||
} | ||
} | ||
|
||
function ignore(_x: any) { return; } |
Oops, something went wrong.