@@ -4,8 +4,9 @@ import * as lambda from '@aws-cdk/aws-lambda';
4
4
import * as cdk from '@aws-cdk/core' ;
5
5
import { Construct } from 'constructs' ;
6
6
import { CfnDeploymentGroup } from '../codedeploy.generated' ;
7
+ import { ImportedDeploymentGroupBase , DeploymentGroupBase } from '../private/base-deployment-group' ;
8
+ import { renderAlarmConfiguration , renderAutoRollbackConfiguration } from '../private/utils' ;
7
9
import { AutoRollbackConfig } from '../rollback-config' ;
8
- import { arnForDeploymentGroup , renderAlarmConfiguration , renderAutoRollbackConfiguration , validateName } from '../utils' ;
9
10
import { ILambdaApplication , LambdaApplication } from './application' ;
10
11
import { ILambdaDeploymentConfig , LambdaDeploymentConfig } from './deployment-config' ;
11
12
@@ -120,10 +121,12 @@ export interface LambdaDeploymentGroupProps {
120
121
/**
121
122
* @resource AWS::CodeDeploy::DeploymentGroup
122
123
*/
123
- export class LambdaDeploymentGroup extends cdk . Resource implements ILambdaDeploymentGroup {
124
+ export class LambdaDeploymentGroup extends DeploymentGroupBase implements ILambdaDeploymentGroup {
124
125
/**
125
126
* Import an Lambda Deployment Group defined either outside the CDK app, or in a different AWS region.
126
127
*
128
+ * Account and region for the DeploymentGroup are taken from the application.
129
+ *
127
130
* @param scope the parent Construct for this new Construct
128
131
* @param id the logical ID of this new Construct
129
132
* @param attrs the properties of the referenced Deployment Group
@@ -137,9 +140,10 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
137
140
}
138
141
139
142
public readonly application : ILambdaApplication ;
140
- public readonly deploymentGroupName : string ;
141
- public readonly deploymentGroupArn : string ;
142
143
public readonly deploymentConfig : ILambdaDeploymentConfig ;
144
+ /**
145
+ * The service Role of this Deployment Group.
146
+ */
143
147
public readonly role : iam . IRole ;
144
148
145
149
private readonly alarms : cloudwatch . IAlarm [ ] ;
@@ -148,16 +152,15 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
148
152
149
153
constructor ( scope : Construct , id : string , props : LambdaDeploymentGroupProps ) {
150
154
super ( scope , id , {
151
- physicalName : props . deploymentGroupName ,
155
+ deploymentGroupName : props . deploymentGroupName ,
156
+ role : props . role ,
157
+ roleConstructId : 'ServiceRole' ,
152
158
} ) ;
159
+ this . role = this . _role ;
153
160
154
161
this . application = props . application || new LambdaApplication ( this , 'Application' ) ;
155
162
this . alarms = props . alarms || [ ] ;
156
163
157
- this . role = props . role || new iam . Role ( this , 'ServiceRole' , {
158
- assumedBy : new iam . ServicePrincipal ( 'codedeploy.amazonaws.com' ) ,
159
- } ) ;
160
-
161
164
this . role . addManagedPolicy ( iam . ManagedPolicy . fromAwsManagedPolicyName ( 'service-role/AWSCodeDeployRoleForLambdaLimited' ) ) ;
162
165
this . deploymentConfig = props . deploymentConfig || LambdaDeploymentConfig . CANARY_10PERCENT_5MINUTES ;
163
166
@@ -174,13 +177,7 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
174
177
autoRollbackConfiguration : cdk . Lazy . any ( { produce : ( ) => renderAutoRollbackConfiguration ( this . alarms , props . autoRollback ) } ) ,
175
178
} ) ;
176
179
177
- this . deploymentGroupName = this . getResourceNameAttribute ( resource . ref ) ;
178
- this . deploymentGroupArn = this . getResourceArnAttribute ( arnForDeploymentGroup ( this . application . applicationName , resource . ref ) , {
179
- service : 'codedeploy' ,
180
- resource : 'deploymentgroup' ,
181
- resourceName : `${ this . application . applicationName } /${ this . physicalName } ` ,
182
- arnFormat : cdk . ArnFormat . COLON_RESOURCE_NAME ,
183
- } ) ;
180
+ this . _setNameAndArn ( resource , this . application ) ;
184
181
185
182
if ( props . preHook ) {
186
183
this . addPreHook ( props . preHook ) ;
@@ -203,8 +200,6 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
203
200
if ( this . deploymentConfig instanceof Construct ) {
204
201
this . node . addDependency ( this . deploymentConfig ) ;
205
202
}
206
-
207
- this . node . addValidation ( { validate : ( ) => validateName ( 'Deployment group' , this . physicalName ) } ) ;
208
203
}
209
204
210
205
/**
@@ -284,17 +279,17 @@ export interface LambdaDeploymentGroupAttributes {
284
279
readonly deploymentConfig ?: ILambdaDeploymentConfig ;
285
280
}
286
281
287
- class ImportedLambdaDeploymentGroup extends cdk . Resource implements ILambdaDeploymentGroup {
282
+ class ImportedLambdaDeploymentGroup extends ImportedDeploymentGroupBase implements ILambdaDeploymentGroup {
288
283
public readonly application : ILambdaApplication ;
289
- public readonly deploymentGroupName : string ;
290
- public readonly deploymentGroupArn : string ;
291
284
public readonly deploymentConfig : ILambdaDeploymentConfig ;
292
285
293
- constructor ( scope :Construct , id : string , props : LambdaDeploymentGroupAttributes ) {
294
- super ( scope , id ) ;
286
+ constructor ( scope : Construct , id : string , props : LambdaDeploymentGroupAttributes ) {
287
+ super ( scope , id , {
288
+ application : props . application ,
289
+ deploymentGroupName : props . deploymentGroupName ,
290
+ } ) ;
291
+
295
292
this . application = props . application ;
296
- this . deploymentGroupName = props . deploymentGroupName ;
297
- this . deploymentGroupArn = arnForDeploymentGroup ( props . application . applicationName , props . deploymentGroupName ) ;
298
293
this . deploymentConfig = props . deploymentConfig || LambdaDeploymentConfig . CANARY_10PERCENT_5MINUTES ;
299
294
}
300
295
}
0 commit comments