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(codedeploy): allow setting a Deployment Configuration for an imp… #3158

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export interface ILambdaDeploymentGroup extends cdk.IResource {
* @attribute
*/
readonly deploymentGroupArn: string;

/**
* The Deployment Configuration this Group uses.
*/
readonly deploymentConfig: ILambdaDeploymentConfig;
}

/**
Expand All @@ -52,7 +57,7 @@ export interface LambdaDeploymentGroupProps {
/**
* The Deployment Configuration this Deployment Group uses.
*
* @default LambdaDeploymentConfig#AllAtOnce
* @default LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES
*/
readonly deploymentConfig?: ILambdaDeploymentConfig;

Expand Down Expand Up @@ -135,6 +140,7 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
public readonly application: ILambdaApplication;
public readonly deploymentGroupName: string;
public readonly deploymentGroupArn: string;
public readonly deploymentConfig: ILambdaDeploymentConfig;
public readonly role: iam.IRole;

private readonly alarms: cloudwatch.IAlarm[];
Expand All @@ -154,12 +160,13 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
});

this.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSCodeDeployRoleForLambda'));
this.deploymentConfig = props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES;

const resource = new CfnDeploymentGroup(this, 'Resource', {
applicationName: this.application.applicationName,
serviceRoleArn: this.role.roleArn,
deploymentGroupName: this.physicalName,
deploymentConfigName: (props.deploymentConfig || LambdaDeploymentConfig.ALL_AT_ONCE).deploymentConfigName,
deploymentConfigName: this.deploymentConfig.deploymentConfigName,
deploymentStyle: {
deploymentType: 'BLUE_GREEN',
deploymentOption: 'WITH_TRAFFIC_CONTROL'
Expand Down Expand Up @@ -262,17 +269,26 @@ export interface LambdaDeploymentGroupAttributes {
* that we are referencing.
*/
readonly deploymentGroupName: string;

/**
* The Deployment Configuration this Deployment Group uses.
*
* @default LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES
*/
readonly deploymentConfig?: ILambdaDeploymentConfig;
}

class ImportedLambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploymentGroup {
public readonly application: ILambdaApplication;
public readonly deploymentGroupName: string;
public readonly deploymentGroupArn: string;
public readonly deploymentConfig: ILambdaDeploymentConfig;

constructor(scope: cdk.Construct, id: string, props: LambdaDeploymentGroupAttributes) {
super(scope, id);
this.application = props.application;
this.deploymentGroupName = props.deploymentGroupName;
this.deploymentGroupArn = arnForDeploymentGroup(props.application.applicationName, props.deploymentGroupName);
this.deploymentConfig = props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -581,5 +581,21 @@ export = {

test.done();
},
}

'imported with fromLambdaDeploymentGroupAttributes': {
'defaults the Deployment Config to Canary10Percent5Minutes'(test: Test) {
const stack = new cdk.Stack();

const lambdaApp = codedeploy.LambdaApplication.fromLambdaApplicationName(stack, 'LA', 'LambdaApplication');
const importedGroup = codedeploy.LambdaDeploymentGroup.fromLambdaDeploymentGroupAttributes(stack, 'LDG', {
application: lambdaApp,
deploymentGroupName: 'LambdaDeploymentGroup',
});

test.equal(importedGroup.deploymentConfig, LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES);

test.done();
},
},
},
};