Skip to content

Commit

Permalink
feat(codedeploy): allow setting a Deployment Configuration for an imp…
Browse files Browse the repository at this point in the history
…orted Lambda Deployment Group. (#3158)
  • Loading branch information
skinny85 authored and Elad Ben-Israel committed Jul 3, 2019
1 parent bd46e49 commit 05a49f0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
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();
},
},
},
};

0 comments on commit 05a49f0

Please sign in to comment.