Skip to content

Commit f6adb7c

Browse files
authoredFeb 27, 2019
fix(codedeploy): LambdaDeploymentGroup now takes IRole (#1840)
Change the arguments of LambdaDeploymentGroup to take interfaces wherever possible. Fixes #1833. BREAKING CHANGE: If an existing role is provided to a LambdaDeploymentGroup, you will need to provide the assuming service principal (`codedeploy.amazonaws.com`) yourself.
1 parent 241ae97 commit f6adb7c

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed
 

‎packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-group.ts

+9-18
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface LambdaDeploymentGroupProps {
4343
*
4444
* @default one will be created for you
4545
*/
46-
application?: LambdaApplication;
46+
application?: ILambdaApplication;
4747

4848
/**
4949
* The physical, human-readable name of the CodeDeploy Deployment Group.
@@ -76,7 +76,7 @@ export interface LambdaDeploymentGroupProps {
7676
*
7777
* @default a new Role will be created.
7878
*/
79-
role?: iam.Role;
79+
role?: iam.IRole;
8080

8181
/**
8282
* Lambda Alias to shift traffic. Updating the version
@@ -124,7 +124,7 @@ export class LambdaDeploymentGroup extends cdk.Construct implements ILambdaDeplo
124124
public readonly application: ILambdaApplication;
125125
public readonly deploymentGroupName: string;
126126
public readonly deploymentGroupArn: string;
127-
public readonly role: iam.Role;
127+
public readonly role: iam.IRole;
128128

129129
private readonly alarms: cloudwatch.Alarm[];
130130
private preHook?: lambda.IFunction;
@@ -136,24 +136,15 @@ export class LambdaDeploymentGroup extends cdk.Construct implements ILambdaDeplo
136136
this.application = props.application || new LambdaApplication(this, 'Application');
137137
this.alarms = props.alarms || [];
138138

139-
let serviceRole: iam.Role | undefined = props.role;
140-
if (serviceRole) {
141-
if (serviceRole.assumeRolePolicy) {
142-
serviceRole.assumeRolePolicy.addStatement(new iam.PolicyStatement()
143-
.addAction('sts:AssumeRole')
144-
.addServicePrincipal('codedeploy.amazonaws.com'));
145-
}
146-
} else {
147-
serviceRole = new iam.Role(this, 'ServiceRole', {
148-
assumedBy: new iam.ServicePrincipal('codedeploy.amazonaws.com')
149-
});
150-
}
151-
serviceRole.attachManagedPolicy('arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda');
152-
this.role = serviceRole;
139+
this.role = props.role || new iam.Role(this, 'ServiceRole', {
140+
assumedBy: new iam.ServicePrincipal('codedeploy.amazonaws.com')
141+
});
142+
143+
this.role.attachManagedPolicy('arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda');
153144

154145
const resource = new CfnDeploymentGroup(this, 'Resource', {
155146
applicationName: this.application.applicationName,
156-
serviceRoleArn: serviceRole.roleArn,
147+
serviceRoleArn: this.role.roleArn,
157148
deploymentGroupName: props.deploymentGroupName,
158149
deploymentConfigName: (props.deploymentConfig || LambdaDeploymentConfig.AllAtOnce).deploymentConfigName,
159150
deploymentStyle: {

‎packages/@aws-cdk/aws-codedeploy/test/lambda/test.deployment-group.ts

-6
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,6 @@ export = {
140140
Principal: {
141141
Service: "not-codedeploy.amazonaws.com"
142142
}
143-
}, {
144-
Action: "sts:AssumeRole",
145-
Effect: "Allow",
146-
Principal: {
147-
Service: "codedeploy.amazonaws.com"
148-
}
149143
}],
150144
Version: "2012-10-17"
151145
},

0 commit comments

Comments
 (0)